HiveBrain v1.2.0
Get Started
← Back to all entries
snippetcsharpCritical

How do I create a message box with "Yes", "No" choices and a DialogResult?

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
boxwithhowchoicesanddialogresultmessageyescreate

Problem

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?

Solution

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
}

Code Snippets

DialogResult dialogResult = MessageBox.Show("Sure", "Some Title", MessageBoxButtons.YesNo);
if(dialogResult == DialogResult.Yes)
{
    //do something
}
else if (dialogResult == DialogResult.No)
{
    //do something else
}

Context

Stack Overflow Q#3036829, score: 952

Revisions (0)

No revisions yet.