Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MessageBox with YesNoCancel - No & Cancel triggers same event

I have a message box with the YesNoCancel buttons...

  • Pressing Yes will do some action and close the application - works fine
  • Pressing No will do nothing and close the application - (see below)
  • Pressing Cancel will do nothing and keep the application open - (see below).

I'm using DialogResult.No for the No button and DialogResult.Cancel for the Cancel button. But pressing either of them triggers DialogResult.Cancel event. What's the problem?

like image 867
Bibhas Debnath Avatar asked Feb 13 '10 08:02

Bibhas Debnath


People also ask

What method do you call to display a message box?

To display a message box, call the static method MessageBox. Show. The title, message, buttons, and icons displayed in the message box are determined by parameters that you pass to this method.


1 Answers

This should work fine:

Dim result As DialogResult = MessageBox.Show("message", "caption", MessageBoxButtons.YesNoCancel) If result = DialogResult.Cancel Then     MessageBox.Show("Cancel pressed") ElseIf result = DialogResult.No Then     MessageBox.Show("No pressed") ElseIf result = DialogResult.Yes Then     MessageBox.Show("Yes pressed") End If 
like image 95
Darin Dimitrov Avatar answered Nov 16 '22 03:11

Darin Dimitrov