Open/close multiple WinForms

JDS

Member
Joined
Mar 12, 2006
Messages
7
Programming Experience
1-3
I am designing a VB.NET program with multiple forms. The base is a "Main Menu" with cmd buttons linking to other input forms. On each input form there is a cmd button to close that form.
I want to close the "Main Menu" and activate an input form when the user clicks the cmd button. When the user wants to close that input form I want the "Main Menu" to return. The user should also be able to click another cmd button to call the same or a different input form and so on.
On the "Main Menu" I did this:
frmLicenseTracker.DefInstance.Close()
frmProduct.DefInstance.ShowDialog()
Me.Show()
On the input form I did this:
Dim dlgResult As DialogResult
dlgResult = MessageBox.Show("Please confirm close", _
"License TracKer - Product", MessageBoxButtons.YesNo, _
MessageBoxIcon.Exclamation)
If dlgResult = DialogResult.Yes Then
Me.Hide()
frmLicenseTracker.DefInstance.ShowDialog()
End If
I also tried:
Me.Close()
frmLicenseTracker.DefInstance.ShowDialog()
Me.Show
and
frmProduct.DefInstance.Hide() [I also tried Close()]
frmLicenseTracker.DefInstance.ShowDialog()
Me.Show [And I tried frmLicenseTracker.DefInstance.Show()]
The "Main Menu" does close (or hides) and the input form appears. When I close the input form the "Main Menu" reappears. When I try to open another form I get the following:

An unhandled exception of type 'System.InvalidOperationException' occurred in system.windows.forms.dll
Additional information: Forms that are already displayed modally cannot be displayed as a modal dialog. Close the form before calling showDialog.
I have looked through this forum and checked VB.NET books with no success - any suggestions?
Thank you very much,
John
 
Havent got time to read through this thoroughly but i would check that you are not trying to use ShowDialog to show the same form. This is because when you close a form that has been shown using ShowDialog it doesn't actually close it, it just hides it.
 
Back
Top