Monday, July 8, 2013

Creating a Child Form in C#

I spent some time this weekend working in C# on a personal project.  One of the subjects I came across was creating a child form.  A child form opens a new form within your current window.

During my research, I came across the following help document:

How to: Create MDI Child Forms

I have a program I created at work that has different tabs for specific tasks that need to be run.  I will be working on migrating from the tabbed format to the child form format, as this seems to be less confusing and the layout looks better.

A few key points for creating a child form:

  1. Create a new windows form in your project for each new window.
  2. Create an event handler for when you click on the button/menu item that will open the new form (Create Event Handler)
  3. Paste the following in your event handler:
protected void MDIChildNew_Click(object sender, System.EventArgs e)
{
   Form2 newMDIChild = new Form2();
   // Set the Parent Form of the Child window.
   newMDIChild.MdiParent = this;
   // Display the new form.
   newMDIChild.Show();
}

No comments:

Post a Comment