I want to make simple Y/N messagebox but I think it is nonsense to design a form for that. I thought I can use MessageBox, add buttons etc. It is simple but since there is no dialog result, I don't know how to retrieve the result?
+2
A:
The MessageBox does produce a DialogResults
DialogResult r = MessageBox.Show("Some question here");
You can also specify the buttons easily enough. More documentation can be found at http://msdn.microsoft.com/en-us/library/ba2a6d06.aspx
David Stratton
2010-06-14 11:34:02
+10
A:
DialogResult dr = MessageBox.Show("Are you happy now?",
"Mood Test", MessageBoxButtons.YesNo);
switch(dr){
case DialogResult.Yes: break;
case DialogResult.No: break;
}
From MessageBox search. MessageBox class is what you are looking for.
SwDevMan81
2010-06-14 11:34:28
A:
MessageBox.Show(title, text, messageboxbuttons.yes/no)
This returns a DialogResult which you can check.
For example,
if(MessageBox.Show("","",MessageBoxButtons.YesNo) == DialogResult.Yes) { //do something }
Ben Cawley
2010-06-14 11:34:40
+2
A:
This should do it:
DialogResult dialogResult = MessageBox.Show("Sure", "Some Title", MessageBoxButtons.YesNo);
if(dialogResult == DialogResult.Yes)
{
//do something
}
else if (dialogResult == DialogResult.No)
{
//do something else
}
Mikael Svenson
2010-06-14 11:37:33