Detect Form Closing
Messages   Related Types
This message was discovered on microsoft.public.dotnet.framework.windowsforms.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.
Post a new message to this list...

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

Reply to this message...
 
    
Herfried K. Wagner [MVP] (VIP)
* "Derek Hart" <Click here to reveal e-mail address> scripsit:
[Original message clipped]

Use 'AddHandler' to add a handler to the 'fFormCriteria''s 'Closed'
event.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Reply to this message...
 
    
Derek Hart
Why would I have to add a handler? Why doesn't the handler trigger since it
is an event in the form?

Derek Hart

"Herfried K. Wagner [MVP]" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
Jeffrey Tan[MSFT] (VIP)
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.

Reply to this message...
 
    
Jeffrey Tan[MSFT] (VIP)
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.

Reply to this message...
 
 
System.ComponentModel.CancelEventArgs
System.EventArgs
System.Object
System.Windows.Forms.Application
System.Windows.Forms.MessageBox




Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
 
 Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us - Terms of Use - Privacy Policy - www.dotnet247.com