yes no message box c# code example
Example 1: c# messagebox yes no
DialogResult dialogResult = MessageBox.Show("Sure", "Some Title", MessageBoxButtons.YesNo);
if(dialogResult == DialogResult.Yes)
{
}
else if (dialogResult == DialogResult.No)
{
}
Example 2: c# yes or no dialog
DialogResult dialogResult = MessageBox.Show("Sure", "Some Title", MessageBoxButtons.YesNo);
if(dialogResult == DialogResult.Yes)
{
}
else if (dialogResult == DialogResult.No)
{
}
Example 3: winforms messagebox with button
string message = "Do you want to close this window?";
string title = "Close Window";
MessageBoxButtons buttons = MessageBoxButtons.YesNo;
DialogResult result = MessageBox.Show(message, title, buttons);
if (result == DialogResult.Yes) {
this.Close();
} else {
}