N
Nathan
I read an earlier post from Gary and answered by Peter Huang concerning
closing one form and showing another. I need to do the same thing in my
application, but the code Peter gave didn't work for me. Maybe Peter or
someone else can help me out.
I changed the startup object to Sub Main, created a new module and inserted
this code:
Imports System.Windows.Forms
Public Module MyApplication
Public formCount As Integer
Public fm1 As Form1
Public fm2 As Form2
Public Sub OnFormClosed(ByVal sender As Object, ByVal e As EventArgs)
formCount = formCount - 1
If (formCount = 0) Then
Application.ExitThread()
End If
End Sub
Public Sub Main()
formCount = 0
fm1 = New Form1
formCount = formCount + 1
fm2 = New Form2
formCount = formCount + 1
AddHandler fm1.Closed, AddressOf OnFormClosed
AddHandler fm2.Closed, AddressOf OnFormClosed
fm1.Show()
Application.Run()
End Sub
End Module
I just changed <Form1> and <Form2> to the names of the two forms with which
I'm working. On each form there is a menu item with a click event that
says:
Me.close
fm2.show
/// or
fm1.show
When I run the application, fm1 appears. I click the menu item, and the fm1
disappears and fm2 appears. I click fm2's menu item, and fm2 disappears and
fm1 appears. However, when I close out of either of the forms, the debugger
continues running, and I have to hit the Stop button to get it to stop.
I have tried replicating this in a brand new application with two forms
named
Form 1 and Form 2, with only a button on each form, and the appropriate
lines in the buttons' click events. I get the same problem.
What's going wrong?
closing one form and showing another. I need to do the same thing in my
application, but the code Peter gave didn't work for me. Maybe Peter or
someone else can help me out.
I changed the startup object to Sub Main, created a new module and inserted
this code:
Imports System.Windows.Forms
Public Module MyApplication
Public formCount As Integer
Public fm1 As Form1
Public fm2 As Form2
Public Sub OnFormClosed(ByVal sender As Object, ByVal e As EventArgs)
formCount = formCount - 1
If (formCount = 0) Then
Application.ExitThread()
End If
End Sub
Public Sub Main()
formCount = 0
fm1 = New Form1
formCount = formCount + 1
fm2 = New Form2
formCount = formCount + 1
AddHandler fm1.Closed, AddressOf OnFormClosed
AddHandler fm2.Closed, AddressOf OnFormClosed
fm1.Show()
Application.Run()
End Sub
End Module
I just changed <Form1> and <Form2> to the names of the two forms with which
I'm working. On each form there is a menu item with a click event that
says:
Me.close
fm2.show
/// or
fm1.show
When I run the application, fm1 appears. I click the menu item, and the fm1
disappears and fm2 appears. I click fm2's menu item, and fm2 disappears and
fm1 appears. However, when I close out of either of the forms, the debugger
continues running, and I have to hit the Stop button to get it to stop.
I have tried replicating this in a brand new application with two forms
named
Form 1 and Form 2, with only a button on each form, and the appropriate
lines in the buttons' click events. I get the same problem.
What's going wrong?