By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,516 Members | 1,369 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,516 IT Pros & Developers. It's quick & easy.

Message box

P: n/a
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
Jul 21 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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" <an*******@discussions.microsoft.com> wrote in message
news:13**********************************@microsof t.com...
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

Jul 21 '05 #2

P: n/a
KS
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" <an*******@discussions.microsoft.com> skrev i en meddelelse
news:13**********************************@microsof t.com...
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

Jul 21 '05 #3

P: n/a
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.InvalidEnumArgumentExceptio n' 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
Jul 21 '05 #4

P: n/a
KS
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" <an*******@discussions.microsoft.com> skrev i en meddelelse
news:B1**********************************@microsof t.com...
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.InvalidEnumArgumentExceptio n' 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?", _ MessageBoxButtons.YesNo, MessageBoxIcon.Question, _
MessageBoxDefaultButton.Button1) = DialogResult.No Then Me.Close()
End If
what do i change to make work?

Luna

Jul 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.