How do I display a MessageBox with Yes and No buttons?
A:
if( MessageBox.Show("Are you sure?", "MessageTitle", MessageBoxButtons.YesNo) == DialogResult.Yes )
MessageBox.Show("You clicked Yes.");
else
MessageBox.Show("You clicked No.");
baeltazor
2009-08-27 13:24:48
For what I can tell by using the same function name all three message boxen have the "yes" and "no" buttons? ;-)
Michael Krelin - hacker
2009-08-27 13:25:51
Erm, I think you're missing a method parameter.
Noldorin
2009-08-27 13:26:14
Should have included the MessageBoxButtons parameter: MessageBox.Show("Are you sure?", "MessageTitle", MessageBoxButtons.YesNo )
TLiebe
2009-08-27 13:26:46
If I were the one who downrated the answer I'd revoke my vote after it's been fixed :-)
Michael Krelin - hacker
2009-08-27 13:27:32
It's still not clear, though, what platform the question applies to:)
Michael Krelin - hacker
2009-08-27 13:28:06
-1 because this looks like C# and default messagebox.show shows only an ok button.
Tony
2009-08-27 13:28:51
i edited my answer because i accidently pressed Ctrl+Enter and it submitted my answer before it was complete
baeltazor
2009-08-27 13:30:07
+7
A:
MessageBox.Show("text", "caption", MessageBoxButtons.YesNo);
.NET / C#
JTA
2009-08-27 13:25:43
+3
A:
if (confirm("Did you want to know how to do it in Javascript?"))
{
alert("You did? Great!");
}
else
{
alert("No? Tag your question with the required language/environment!");
}
Or alternatively,
int result = MessageBox(
NULL,
(LPCWSTR)L"So, did you want a Win32 example?",
(LPCWSTR)L"OK, the javascript one was flawed",
MB_ICONQUESTION | MB_YESNO
);
or maybe
int result = AfxMessageBox("Do people still use MFC?",
MB_ICONQUESTION | MB_YESNO);
Paul Dixon
2009-08-27 13:29:20