Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 616
  • Last Modified:

Perfom action on the mdi parent form when child form close

Hi
I want to perform an action when a child from closes on the parent form.

Any ideas on how to do this?
0
delta_v
Asked:
delta_v
1 Solution
 
macksmCommented:
try calling a global  function from  WM_CLOSE or WM_QUIT message handler of the child window
0
 
Fernando SotoCommented:
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
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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
 
delta_vAuthor Commented:
Idle Mind

How do i do that?
0
 
delta_vAuthor Commented:
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

Tackle projects and never again get stuck behind a technical roadblock.
Join Now