如何创建带有“是”、“否”的消息框选择和 DialogResult?
我想制作简单的是/否选择的消息框,但我认为为此设计一个表单是无意义的。我想我可以使用 MessageBox、添加按钮等来完成此任务。很简单,但是由于没有返回DialogResult,如何检索结果呢?
I want to make simple Yes/No choiced MessageBox, but I think it is nonsense to design a form for that. I thought I could use MessageBox, add buttons, etc. to accomplish this. It is simple, but since there is no DialogResult returned, how do I retrieve the result?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(11)
这应该可以做到:
This should do it:
MessageBox 类就是您正在寻找的。
MessageBox class is what you are looking for.
这将返回一个 DialogResult,您可以检查它。
例如,
This returns a DialogResult which you can check.
For example,
MessageBox 确实生成 DialogResults
您还可以轻松指定按钮。更多文档可以在 http://msdn.microsoft.com/en-us 找到/library/ba2a6d06.aspx
The MessageBox does produce a DialogResults
You can also specify the buttons easily enough. More documentation can be found at http://msdn.microsoft.com/en-us/library/ba2a6d06.aspx
使用:
Windows Phone上使用MessageBoxResult而不是DialogResult...
Use:
MessageBoxResult is used on Windows Phone instead of DialogResult...
您还可以将此变体与文本字符串一起使用,这是完整更改的代码(来自 Mikael 的代码),在 C# 2012 中测试:
您可以在
插入消息图标后
You can also use this variant with text strings, here's the complete changed code (Code from Mikael), tested in C# 2012:
You can after
insert a message icon
@Mikael Svenson 的答案是正确的。我只是想添加一个小补充:
消息框图标也可以包含一个附加属性,如下所示:
@Mikael Svenson's answer is correct. I just wanted to add a small addition to it:
The Messagebox icon can also be included has an additional property like below:
试试这个:
Try this:
这个简单的代码对我有用。我从 MSDN 中获取了它:
https://social.msdn.microsoft.com/Forums/en-US/d1092a96-96b0-4ca4-b716-0c8e55e42ee9/how-can-i-manage-messagebox -结果-?forum=Vsexpressvcs
This simple code worked for me. I grabbed it from MSDN here:
https://social.msdn.microsoft.com/Forums/en-US/d1092a96-96b0-4ca4-b716-0c8e55e42ee9/how-can-i-manage-messagebox-result-?forum=Vsexpressvcs
从此处查看更多详细信息
Check more detail from here