I want to code on message box buttons in vb.net. It should perform a specific task of my choice when clicked
Asked
Active
Viewed 54 times
-1
-
2Does this answer your question? [MessageBox with YesNoCancel - No & Cancel triggers same event](https://stackoverflow.com/questions/2256909/messagebox-with-yesnocancel-no-cancel-triggers-same-event) – 41686d6564 stands w. Palestine Dec 08 '19 at 12:27
1 Answers
2
You can check the DialogResult
to perform specific code for the different buttons available on the MessageBox
. See the following example:
Dim dlgResult As DialogResult = MessageBox.Show("Your Message", "Your Caption", MessageBoxButtons.YesNo)
If dlgResult = System.Windows.Forms.DialogResult.Yes Then
'Code on Yes
ElseIf dlgResult = System.Windows.Forms.DialogResult.No Then
'Code on No
End If

Sebastian Brosch
- 42,106
- 15
- 72
- 87