Solved

Perfom action on the mdi parent form when child form close

Posted on 2009-07-05
5
588 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
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 62

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 85

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Connection String 16 56
Help with C#, MVC, razor. 6 34
Hey!!!! 1 20
How to parse the string and split the sub directory names in asp.net 7 41
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

776 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