Aleksandr Storozhuk Aleksandr Storozhuk - 24 days ago 9
C# Question

MessageBox closed event

I have MessageBox only with

Ok
button, although there's close button. But in code I can check only
DialogResult.Ok
.
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

You can do this way,

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

 }
 else if (result == DialogResult.Cancel)
 {

 }