Solved

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

Posted on 2011-03-23
6
823 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Quiz: What Do These Organizations Have In Common?

Hint: Their teams ended up taking quizzes, too.

 
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

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

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

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
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…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

734 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