I am attempting to execute some code when a second form is closed, and have been at this for some time with no luck as of yet except to know this is my obsticle after some testing.

I had thought it may be in the reference of the second form in the command for calling the event, but found I could not label it to the name of the second form.

I am using the following event to run when the second form, called "options", is closed or is closing...

Private Sub options_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing

I know there are two similar events; FormClosing and FormClosed. I am unsure which would be more appropriate to use, but logically I am thinking FormClosing as the variable I wish to pass is still 'alive'?

OR, am I going about this with the wrong method? Does this event handle only the current form?

THANKS!

-Tom

Recommended Answers

All 4 Replies

From the way I see it , your approch is correct , form_closing fires up when the form is about to close , question is , what information are you trying to pass , I assume that you are passing some options from the toolwindow to the main window , and is theoption window modal ?
One last thing , form_closing doesn't recognize the parent form , it only recognizes the form (object) from which it was fired up

From the way I see it , your approch is correct , form_closing fires up when the form is about to close , question is , what information are you trying to pass , I assume that you are passing some options from the toolwindow to the main window , and is theoption window modal ?
One last thing , form_closing doesn't recognize the parent form , it only recognizes the form (object) from which it was fired up

y2_sub,

THANKS for replying! I call the form modal:

options.ShowDialog() ' Modal

However, the event is being called on the main form (Form1) so perhaps that is why I am not seeing anything execute. If the FormClosing and FormClosed events are for the current form only, then I need to use another method for the main form to show a variable passed when the second form is closed.

I can easily do this from the second form 'options', however it is desired to be done form the main form itself, 'Form1'. Hmmm...

y2_sub,

THANKS for replying! I call the form modal:

options.ShowDialog() ' Modal

However, the event is being called on the main form (Form1) so perhaps that is why I am not seeing anything execute. If the FormClosing and FormClosed events are for the current form only, then I need to use another method for the main form to show a variable passed when the second form is closed.

I can easily do this from the second form 'options', however it is desired to be done form the main form itself, 'Form1'. Hmmm...

You can still handle the second form events from the main form that lunched it by adding an event handler

Dim optionsForm As New options
        AddHandler optionsForm.FormClosing, AddressOf Option_formClosing ' Add The Event Handler
        optionsForm.ShowDialog()
Private Sub Option_formClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) ' Add Handling Events Here on the main window

    End Sub

Thanks, I've got the concept of it now ^5 We're about 45% complete on our project. Then we're going to test it on a couple kids LOL.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.