Solved

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

Posted on 2011-03-23
6
787 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 85

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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 85

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 85

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
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…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

746 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now