如何创建一个消息框,"是","否];选择和的DialogResult?
问题描述:
我想进行简单的是/否choiced消息框,但我认为这是无稽之谈设计一个表格的。我以为我可以使用的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?
答
这应该这样做:
DialogResult dialogResult = MessageBox.Show("Sure", "Some Title", MessageBoxButtons.YesNo);
if(dialogResult == DialogResult.Yes)
{
//do something
}
else if (dialogResult == DialogResult.No)
{
//do something else
}