[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Closing a child form from an mdi container

Posted on 2005-05-11
5
Medium Priority
?
195 Views
Last Modified: 2010-04-16
On my container there are buttons that when clicked a form pops up. What I want to happen is when the next button is clicked the form that is in focus is closed and the next form appears in its place. Here is what i have so far:

private void button2_Click(object sender, System.EventArgs e)
            {
                  Form3 form3 = new Form3();
                  form3.Show();
                  button6.Enabled = true;
                  button5.Enabled = true;
                  button4.Enabled = true;
                  button3.Enabled = true;
                  button2.Enabled = false;
            }
0
Comment
Question by:TerryBurger
  • 2
  • 2
5 Comments
 
LVL 9

Expert Comment

by:cyberdevil67
ID: 13986882
Form2 form2 = null;
Form3 form3 = null;

private void button3_Click(object sender, System.EventArgs e)
          {
               form2.Close();
               form3 = new Form3();
               form3.Show();
          }
0
 
LVL 9

Expert Comment

by:BurntSky
ID: 13988698
This should close the first open Mdi Child, if one exists.  If more than one window could be open at a time and you want to close them all, you could just create a for loop.

private void button2_Click(object sender, System.EventArgs e)
{
    if(this.MdiChildren.Length > 0) this.MdiChildren[0].Close();
    Form3 form3 = new Form3();
    form3.Show();
}
0
 

Author Comment

by:TerryBurger
ID: 13999237
the this.MdiChildren[0].Close(); didn't work maybe I'm not defining my other pages as Mdichildren correctly. In order for that statement to work how should I go about doing that?
0
 
LVL 9

Accepted Solution

by:
BurntSky earned 1000 total points
ID: 14000609
What do you mean it "didn't work"?  Did you get an error of some sort?  Or did the form just not close?  You have to be more specific when speaking about problems with code if you want to get good answers.

Defining the Mdi children should be pretty straight forward:

Form2 form2 = new Form2();
form2.MdiParent = this;
form2.Show();

Try doing a foreach or for loop:

foreach(Form form in this.MdiChildre)
    form.Close();
0
 
LVL 9

Expert Comment

by:cyberdevil67
ID: 14000920
If you are doing this in you MDI container


  Form form1 = new myForm();

 then you can just do this

 form1.close();

0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

872 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