views:

168

answers:

3

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
For what I can tell by using the same function name all three message boxen have the "yes" and "no" buttons? ;-)
Michael Krelin - hacker
Erm, I think you're missing a method parameter.
Noldorin
Should have included the MessageBoxButtons parameter: MessageBox.Show("Are you sure?", "MessageTitle", MessageBoxButtons.YesNo )
TLiebe
If I were the one who downrated the answer I'd revoke my vote after it's been fixed :-)
Michael Krelin - hacker
It's still not clear, though, what platform the question applies to:)
Michael Krelin - hacker
-1 because this looks like C# and default messagebox.show shows only an ok button.
Tony
i edited my answer because i accidently pressed Ctrl+Enter and it submitted my answer before it was complete
baeltazor
+7  A: 
MessageBox.Show("text", "caption", MessageBoxButtons.YesNo);

.NET / C#

JTA
+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
Except for that would be "Ok", "Cancel" ;-)
Michael Krelin - hacker
Shhhhhhhhhhh! :)
Paul Dixon