Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2011-03-23
6
Medium Priority
?
835 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
Command Line Tips and Tricks

The command line is a powerful tool at the disposal of every Linux user. Although Linux distros come with beautiful user interfaces, it's worthwhile to learn the command line because it allows you to do a number of things that you otherwise cannot do from the GUI.  

 
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 2000 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
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…
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…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

670 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