Click here to Skip to main content
15,887,083 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
which event can be used to identify any opened childform is closed?
i need this to be detected from MDi parent form...
Posted

Here is the idea: who needs MDI, ever? Why torturing yourself and scaring off your users?
Do yourself a great favor: do not use MDI at all. You can do much easier to implement design without it, with much better quality. MDI is highly discouraged even by Microsoft, in fact, Microsoft dropped it out of WPF and will hardly support it. More importantly, you will scare off all your users if you use MDI. Just don't. Please see:
http://en.wikipedia.org/wiki/Multiple_document_interface#Disadvantages[^],
How to Create MDI Parent Window in WPF?[^].

I can explain what to do instead. Please see my past answers:
How to Create MDI Parent Window in WPF? [Solution 2],
Question on using MDI windows in WPF[^],
MDIContainer giving error[^],
How to set child forms maximized, last childform minimized[^].

—SA
 
Share this answer
 
Comments
Maciej Los 7-Apr-13 5:30am    
+5!
Sergey, "Who needs MDI forms ever?" - this is very good subject for new article. What you think about it?
Sergey Alexandrovich Kryukov 7-Apr-13 11:53am    
Thank you, Maciej. No, I don't think it's a subject for an article at all.
—SA
Maciej Los 7-Apr-13 12:01pm    
Why? It would be a complete guide (tip) why not to use MDI forms ;)
Sergey Alexandrovich Kryukov 7-Apr-13 12:07pm    
In principle, yes, but it's a bad idea to put some negative fact in the center. Do you see what do I mean. Think who would want to read it and why...
Besides, two my articles with fully written software wait for completion, some more in different less elaborate stages... and each of them is way more interesting...
—SA
Maciej Los 7-Apr-13 12:26pm    
I don't see it in this way... but now i understand your attitude ;)
In my point of view, is to show alternative ways, shortly describing the reasons why not to use MDI forms...
Many times i have read in your answers that there are much easier ways to achieve equivalent design (User Interface).
Do you understand my motivation now? It could be very interesting...
try this code..
C#
private void button1_Click(object sender, EventArgs e)
        {
            Form1 frm1 = new Form1();
            frm1.FormClosed += new FormClosedEventHandler(MdiChildClosing);
            frm1.MdiParent = this;
            frm1.Show();
        }
        private void MdiChildClosing(object sender, FormClosedEventArgs e)
        {
            Form frmg = (Form)sender;
            MessageBox.Show(sender.GetType().Name.ToString());
            MessageBox.Show("Form closed");
        }
 
Share this answer
 
v2
Comments
Maciej Los 7-Apr-13 5:35am    
+5!
Add new event handler is a good idea!
This method will help you to work with MDI Doc. Implement this method in your main form (MDI Parent)

C#
public void LaunchChildForm(Form ChildForm)
  {
      bool FormAlreadyExists = false;
      foreach (Form myForm in MdiChildren)
      {
          if (myForm.GetType() == ChildForm.GetType())
          {
              FormAlreadyExists = true;
              ChildForm = myForm;
              break;
          }
      }
      if (FormAlreadyExists == true)
      {
          ChildForm.BringToFront();
      }
      else
      {
          ChildForm.MdiParent = this;
          ChildForm.WindowState = FormWindowState.Normal;
          ChildForm.Show();

      }

  }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900