- Dec 2, 2002
- 1,916
- 0
- 0
I am having a problem closing all forms in my VB .Net application. I have a Login form, which opens a subform called Main. Main has several forms which it may open (think of main menu). When I click on the X button in the top right corner in Login or Main, the app closes properly. However if I hit X in any other screen, it remains running but doesn't show any visible signs of this; I see that it is running in the task manager, but I don't see any open windows.
------------------------------------------------------------------------------------------------------------------------
When I login from Login to Main, I use the following code:
Dim mainForm As New Main(Me)
Me.Hide()
mainForm.Show()
------------------------------------------------------------------------------------------------------------------------
Main looks like this... the constructor and the close/finalize Subs are shown.
Public Class MapForm
Inherits System.Windows.Forms.Form
Dim parent_form As Form
Public Sub New(ByRef p As Form)
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
parent_form = p
End Sub
Public Sub Form_Closed(ByVal sender As System.Object, ByVal e As EventArgs) Handles MyBase.Closed
Finalize()
End Sub
Protected Overrides Sub finalize()
MsgBox("test")
Dim er As System.Exception
Try
Dim pack As New Packet()
pack.Type = Packet.LOGOUT
Packet.writePacket(stream, pack)
parent_form.Close()
Close()
Catch er
End Try
End Sub
------------------------------------------------------------------------------------------------------------------------
The relationship between the subforms of Main and Main is the same as Main and Login (in terms of the constructor and close/finalize). However, closing only works for Main and Login, and not the subforms of Main. So my question is, how do I fix this problem?
I may have been vague in my explanation, so if you have any questions please ask away.
Thanks!
------------------------------------------------------------------------------------------------------------------------
When I login from Login to Main, I use the following code:
Dim mainForm As New Main(Me)
Me.Hide()
mainForm.Show()
------------------------------------------------------------------------------------------------------------------------
Main looks like this... the constructor and the close/finalize Subs are shown.
Public Class MapForm
Inherits System.Windows.Forms.Form
Dim parent_form As Form
Public Sub New(ByRef p As Form)
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
parent_form = p
End Sub
Public Sub Form_Closed(ByVal sender As System.Object, ByVal e As EventArgs) Handles MyBase.Closed
Finalize()
End Sub
Protected Overrides Sub finalize()
MsgBox("test")
Dim er As System.Exception
Try
Dim pack As New Packet()
pack.Type = Packet.LOGOUT
Packet.writePacket(stream, pack)
parent_form.Close()
Close()
Catch er
End Try
End Sub
------------------------------------------------------------------------------------------------------------------------
The relationship between the subforms of Main and Main is the same as Main and Login (in terms of the constructor and close/finalize). However, closing only works for Main and Login, and not the subforms of Main. So my question is, how do I fix this problem?
I may have been vague in my explanation, so if you have any questions please ask away.
Thanks!