haroldjclements Posted March 31, 2005 Posted March 31, 2005 Hello All, If I have a MessageBox with an 'Ok' and a 'Cancel', how do I create a function (or method) for each of these buttons? e.g. If I press 'Ok' it will access the new form and if I press 'Cancel' it remains in the form from which the button was originally pressed. Any help will be very much appreciated. Thanks, Harold Clements Quote
pendragon Posted March 31, 2005 Posted March 31, 2005 Define a variable as type DialogResult then yourvariable = Messagebox.Show(......) if (yourvariable = DialogResult.OK) Quote
Leaders snarfblam Posted March 31, 2005 Leaders Posted March 31, 2005 Save yourself a couple lines of code. I think these would also be easier to read. Select Case MessageBox.Show("Message", "Caption", MessageBoxButtons.OKCancel) Case DialogResult.OK 'Code here Case DialogResult.Cancel 'Code here End Select '-------OR--------' If MessageBox.Show("Message", "Caption", MessageBoxButtons.OKCancel) = DialogResult.OK Then 'Code here Else 'User clicked Cancel 'Code here End If Quote [sIGPIC]e[/sIGPIC]
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.