easy forms question

  • Thread starter Thread starter Paul M
  • Start date Start date
P

Paul M

I have two forms in a sample application, in my sub Main() i start the main
one - Application.Run(form1)

in the first form i have a button that opens up form 2:

Dim f2 as new form2
f2.showdialog()


now, this is where i hit the problem, i have code in a button that validates
user entry, but if an error returns i show a messagebox, but when i cliek OK
or CANCEL, it closes the dialog, but also closes the form!!!!

does this mean that i need to use Application.Run(f2) to keep it open also?

thanks,
Paul.
 
I have two forms in a sample application, in my sub Main() i start the main
one - Application.Run(form1)

in the first form i have a button that opens up form 2:

Dim f2 as new form2
f2.showdialog()


now, this is where i hit the problem, i have code in a button that validates
user entry, but if an error returns i show a messagebox, but when i cliek OK
or CANCEL, it closes the dialog, but also closes the form!!!!

You're saying that clicking the OK or CANCEL buttons in the messagebox
closes your entire application? Is this happening inside form2 (while
it's shown modally) or in form1 after the "f2.showDialog" code?
 
You say that the validation code is in a button on Form2. Does that button have a DialogResult property (other than None)? If so, you must set the DialogResult to DialogResult.None after displaying the message box in order to keep Form2 open.
 
no, it doesnt close my entire application, it just closes the modal form
(2nd form)
the second form is shown modally, then the messagebox appears, and after
selection of OK or CANCEL, it closes the messagebox, but also the second
form.

example:

main form opens frmSettings. In frmSetting i have a Save button, which has
validation code.. if X=1 then...etc etc..
if it finds a validation error, it shows a messagebox, where i check like
the following:

If MessageBox.Show("Cancel the wizard?", "Cancel", MessageBoxButtons.YesNo,
MessageBoxIcon.Question) = DialogResult.Yes Then Me.Close()


Hope it helps,
Paul.
 
aah yes, my Cancel button was set DialogResult = CANCEL, i put this so i
could press escape and the modal form could cancel.
Within this button, i have validation to make sure the user wants to cancel.

If they click No, can i set the dialogresult=none, which will keep the form
open???

thanks,
Paul.
 
Back
Top