Solved

Perfom action on the mdi parent form when child form close

Posted on 2009-07-05
5
606 Views
Last Modified: 2012-05-07
Hi
I want to perform an action when a child from closes on the parent form.

Any ideas on how to do this?
0
Comment
Question by:delta_v
[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
5 Comments
 
LVL 4

Expert Comment

by:macksm
ID: 24779944
try calling a global  function from  WM_CLOSE or WM_QUIT message handler of the child window
0
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 24780167
Hi delta_v;

Use the childs Closing or Closed events to perform the action on the MDI parent form. See code snippet.

Fernando
// MID Parent Form
 
public partial class MDIParent : Form
{
    public MDIParent()
    {
        InitializeComponent();
    }
 
    private void createChildToolStripMenuItem_Click(object sender, EventArgs e)
    {
        ChildForm cf = new ChildForm();
        cf.TopLevel = false;
        cf.Parent = this;
        cf.Show();
    }
 
    public void DisplayMessage(string msg)
    {
        MessageBox.Show(msg);
    }
}
 
// Child Form
 
public partial class ChildForm : Form
{
    public ChildForm()
    {
        InitializeComponent();
    }
 
    // Calling function in MDIParent form BEFORE child form is closed
    private void ChildForm_FormClosing(object sender, FormClosingEventArgs e)
    {
        ((MDIParent)this.Parent).DisplayMessage("Child Form Closing");
    }
 
    // Calling function in MDIParent form AFTER child form is closed
    private void ChildForm_FormClosed(object sender, FormClosedEventArgs e)
    {
        ((MDIParent)this.Parent).DisplayMessage("Child Form Closed");
    }
}

Open in new window

0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 24780920
Instead of driving the behaviour from within the child itself, subscribe to the childs FormClosing() event in the MdiParent when the child is created...
0
 
LVL 1

Author Comment

by:delta_v
ID: 24797435
Idle Mind

How do i do that?
0
 
LVL 1

Author Comment

by:delta_v
ID: 24797515
Thanks, i found how to do it on the following website, it does exacly what i need

http://www.dotnetcurry.com/ShowArticle.aspx?ID=125&AspxAutoDetectCookieSupport=1
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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 …
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

627 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