Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MessageBoxButton.YesNo Tutorial

Tags:

c#

I have a little problem again but this time it regards the MessageBoxButton.YesNo. This is my problem: I don't know what's the right syntax so that if I hit Enter(keyboard) or click Yes, the Application.Exit(); will execute and if I hit Esc(keyboard) or click No, the Application.Exit(); will not execute. This is my code:

MessageBox.Show("Are you sure you want to exit?","Application Exit", MessageBoxButtons.YesNo);
Application.Exit();
like image 535
Yukimoto Otomikuy Avatar asked Dec 02 '22 23:12

Yukimoto Otomikuy


1 Answers

You need to actually store off and check the result of the message box

var result = MessageBox.Show("Are you sure you want to exit?", "Application Exit", MessageBoxButtons.YesNo);
if (result == DialogResult.Yes)
{
    Application.Exit();
}
like image 150
Nick Freeman Avatar answered Dec 17 '22 22:12

Nick Freeman