Aleksandr Storozhuk Aleksandr Storozhuk - 1 year ago 91
C# Question

MessageBox closed event

I have MessageBox only with

button, although there's close button. But in code I can check only
How should I check which button user had pressed?
Only as
if (MessageBox("error") != DialogResult.Ok)
or there's another way?
Is any event, that occures, when user closes MessageBox?

Answer Source

You can do this way,

 DialogResult result = MessageBox.Show("Message", "Tests", MessageBoxButtons.OKCancel);
 if (result == DialogResult.OK)

 else if (result == DialogResult.Cancel)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download