Message box

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

Can someone tell me how i could close a form if the 'OK' button is clicked in a message box.

i have attempted something like the following....

Private Sub Button2_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
MsgBox("If you continue, u will lose the current booking. Do you wish to continue?",
vbOKCancel)
If vbOK Then Me.Close() Else
End Sub

Also how do i place icons in the message box for this type of warning message?

Thank you
 
Use the new MessageBox instead of MsgBox (the old can do the same but ... up
to date you know !))

If MessageBox.Show("Do you want to close ?", _
MessageBoxButtons.YesNo, MessageBoxIcon.Question, _
MessageBoxDefaultButton.Button1) = DialogResult.No Then
..
what to do if closing.
..
Else
..
what to do else
..
End If

KS, Denmark


Luna said:
Hi,

Can someone tell me how i could close a form if the 'OK' button is clicked in a message box.

i have attempted something like the following....

Private Sub Button2_Click_1(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
 
this.Close(); or whatever form reference you have will close the form.

To get an ICON there is an override for MessageBox(... with MessageBoxIcon
enum or something as a parameter.



Luna said:
Hi,

Can someone tell me how i could close a form if the 'OK' button is clicked in a message box.

i have attempted something like the following....

Private Sub Button2_Click_1(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
 
Hi

i have tried your code but i cannot seem to get it to work!
this is what i tried, but im gettin an error that says

An unhandled exception of type 'System.ComponentModel.InvalidEnumArgumentException' occurred in system.windows.forms.dl

Additional information: Enum argument value 32 is not valid for buttons. buttons should be a value from DialogResult

If MessageBox.Show("If you continue, you will lose the current booking. Do you wish to continue?",
MessageBoxButtons.YesNo, MessageBoxIcon.Question,
MessageBoxDefaultButton.Button1) = DialogResult.No The
Me.Close(
End I

what do i change to make work

Luna
 
Hi Luna

I think I have made a mistake - I think you should test for the
DialogResult.No - I think you too have mede the same error in your sample -
but it can't be the only problem.

Try to see the yellow tooltip for each of the parameters in the
MessageBox.Show.

What about your 'line breakes' - is there a space before the underscore ?

- it should be a peace of cake.

KS, Denmark

Luna said:
Hi,

i have tried your code but i cannot seem to get it to work!!
this is what i tried, but im gettin an error that says:

An unhandled exception of type
'System.ComponentModel.InvalidEnumArgumentException' occurred in
system.windows.forms.dll
Additional information: Enum argument value 32 is not valid for buttons.
buttons should be a value from DialogResult.
If MessageBox.Show("If you continue, you will lose the current
booking. Do you wish to continue?", _
 
Back
Top