Windows. Forms as a reference in your project. Right-click on 'References' , select 'Add Reference' and look under Assemblies in the dialogue. If you created your project as a Windows Forms project, that reference should have been added for you automatically.
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.
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.
}
MessageBox.Show
? You can specify the title, caption, and a few options for which buttons to display.
On the other hand, if you're asking people to confirm information, that sounds like you probably want to show a custom dialog - which you can do with Form.ShowDialog
.
In .Net Core
you can do it like this:
DialogResult dialogResult= MessageBox.Show("Are you sure to delete?", "Confirm", MessageBoxButtons.YesNo);
if (dialogResult == DialogResult.Yes)
{
//if code here....
}
else
{
//else code here....
}
Output Result
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With