views:

40

answers:

2

I have 2 forms. Form1 and Form2.

When Form2 is closing, how do I make Form2 to inform Form1 that Form2 is closed.

Do I need to use Delegate, if yes, how?

thanks.

A: 

You can just create a custom event in Form2 and then make Form1 subscribe to it. Here's a nice and easy tutorial article for this:

http://www.codeproject.com/KB/vb/StepByStepEventsInVBNET.aspx

Edit: If you just need the event when it's closing, I'd go with Oded's solution since that's easier.

ho1
+1  A: 

You will need to first reference Form2 from Form1, then you can use one of the close events on the other form. Either the Form.OnClosed or Form.OnClosing events.

' On form1
Private Sub Form2_Closing(ByVal sender As Object, _
     ByVal e As EventArgs) Handles Form2.OnClosing

    ' Form2 informed us that it is closing. Do stuff!

End Sub
Oded
do you mind telling me how to do the reference Form2 from Form1, as without doing the referencing i can't see Form2 Closing event. tkx.
jameslcs
How are you opening Form2? How are you opening Form1? You do that using references to both. I can't really help more without seeing more of your current code.
Oded
'i just add Form2 using right click -> Add Windows Form and use ShowDialog() to show Form2 from Form1
jameslcs
And what are you calling `ShowDialog()` on? A reference to Form2...
Oded
after some further reading, i got it.thanks Oded and Ho for your help.
jameslcs