Solved

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

Posted on 2011-03-23
6
827 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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
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…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

635 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