Solved

How to signal the Close event of a a MDI child frame to the parent frame

Posted on 2011-03-23
6
814 Views
Last Modified: 2012-05-11
In vb.net how can I alert the parent MDI frame that a child has closed ?
May a be stupid question but I am somehow stuck on that.

Thanks for any help.
0
Comment
Question by:Phyllax
  • 3
  • 2
6 Comments
 
LVL 18

Expert Comment

by:lludden
ID: 35199938
Listen for the close event on the object in the parent.

Dim ofrm as new form
addhandler ofrm.Close, addressof childforms_closing
ofrm.show
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 35200105
* Not for points *

The event is typically FormClosed():   (unless you're suing VB.Net 2003 or below)
http://msdn.microsoft.com/en-us/library/system.windows.forms.form.formclosed(VS.80).aspx
0
 

Author Comment

by:Phyllax
ID: 35200484
I still have a problem to ge this work.
Problem is that there appears to be no "Close" event for Windows forms !?
I therefore tried the "Closed" keyword, but this doesn't work either.

As a test I established two forms (Form1 and Form2).
Form1 is MDI container. Both forms have one button control "Button1".

Form1 Code is:

Public Class Form1
    Dim ChildForm As New Form2
    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Form2.Show()
    End Sub

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        AddHandler ChildForm.Closed, AddressOf Childform_Terminated
    End Sub

    Private Sub Childform_Terminated()
        MsgBox("Return")
    End Sub
End Class

Form 2 code is:

Public Class Form2

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Me.Close()
    End Sub
End Class


What am I doing wrong ?
0
Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 35200511
Something like:
Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim f2 As New Form2
        f2.MdiParent = Me
        AddHandler f2.FormClosed, AddressOf Child_FormClosed
        f2.Show()
    End Sub

    Private Sub Child_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs)
        MessageBox.Show("Child form closed!")
    End Sub

End Class

Open in new window

0
 

Author Comment

by:Phyllax
ID: 35200614
I am sorry but the event is still not firing (or captured) !

Public Class Form1

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Dim ChildForm As New Form2
        Form2.MdiParent = Me
        AddHandler ChildForm.FormClosed, AddressOf Childform_Terminated
        Form2.Show()
    End Sub

    Private Sub Childform_Terminated()
        MsgBox("Child form closed")
    End Sub

End Class
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 35200643
That's because you are creating an instance of Form2 called "ChildForm"...but then you are NOT using it.

Change this:

    Form2.MdiParent = Me

To:

    ChildForm.MdiParent = Me

-----------------------------------------------------

And change this:

    Form2.Show()

To:

    ChildForm.Show()
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question