Yukimoto Otomikuy Yukimoto Otomikuy - 3 years ago 103
C# Question

MessageBoxButton.YesNo Tutorial

I have a little problem again but this time it regards the

. This is my problem: I don't know what's the right syntax so that if I hit Enter(keyboard) or click Yes, the
will execute and if I hit Esc(keyboard) or click No, the
will not execute. This is my code:

MessageBox.Show("Are you sure you want to exit?","Application Exit", MessageBoxButtons.YesNo);

Answer Source

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)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download