Detect Form Closing

  • Thread starter Thread starter Derek Hart
  • Start date Start date
D

Derek Hart

I have a main form that is open by using: Application.Run(New
fFormCriteria)

And then I have a form that runs invisible that is open by using: Dim
myForm As New fVersionTimer

The fFormCriteria form is the form that the user will close to exit the
program. How do I detect the Form_Closing event on frmVersionTimer? Is it
possible?

Derek Hart
 
* "Derek Hart said:
I have a main form that is open by using: Application.Run(New
fFormCriteria)

And then I have a form that runs invisible that is open by using: Dim
myForm As New fVersionTimer

The fFormCriteria form is the form that the user will close to exit the
program. How do I detect the Form_Closing event on frmVersionTimer? Is it
possible?

Use 'AddHandler' to add a handler to the 'fFormCriteria''s 'Closed'
event.
 
Why would I have to add a handler? Why doesn't the handler trigger since it
is an event in the form?

Derek Hart
 
Hi Derek,

You may pass the main form's reference to the hidden form, then in the
hidden form(fVersionTimer), add the closing eventhandler for the main form.
Code like this:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim f2 As New Form2(Me)
End Sub

'In Form2, create a new constructor for passing Form1's reference
Dim p As Form1
Public Sub New(ByVal parent As Form1)
MyBase.New()

Me.p = parent
AddHandler Me.p.Closing, AddressOf ParentForm_Closing
'This call is required by the Windows Form Designer.
InitializeComponent()

End Sub

Public Sub New()
MyBase.New()


'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub

Private Sub ParentForm_Closing(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs)
MessageBox.Show("abc")
End Sub

=======================================
Please apply my suggestion above and let me know if it helps resolve your
problem.

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Hi Derek,

Does my reply make sense to you? Is your problem resolved? Please feel free
to tell me. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Back
Top