0

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?

Jim
  • 2,974
  • 2
  • 19
  • 29

1 Answers1

5

You can do this way,

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

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

 }
Jules
  • 567
  • 1
  • 6
  • 15
Sajeetharan
  • 216,225
  • 63
  • 350
  • 396