Is there a builtin confirmation dialog in Windows Forms?

delete picture delete · Oct 2, 2010 · Viewed 91.8k times · Source

I'd like to create a simple confirm dialog saying "Please check the information and if you're sure it's correct, click OK."

Is there something built in like this?

Answer

Raaghav picture Raaghav · Jan 4, 2013

Here is an example. You can try something like this.

var confirmResult =  MessageBox.Show("Are you sure to delete this item ??",
                                     "Confirm Delete!!",
                                     MessageBoxButtons.YesNo);
if (confirmResult == DialogResult.Yes)
{
    // If 'Yes', do something here.
}
else
{
    // If 'No', do something here.
}

You can also try MessageBoxButtons.OKCancel instead of MessageBoxButtons.YesNo. It depends on your requirements.

  1. If you have .Net Framework 4.6 or above please try this.
MessageBoxResult confirmResult = MessageBox.Show("Are you sure to delete this item ??", "Confirm Delete!!", MessageBoxButton.YesNo);`

if (confirmResult == MessageBoxResult.Yes)
{
   // If 'Yes', do something here.
}
else
{
   // If 'No', do something here.
}