Blue Theme Orange Theme Green Theme Red Theme
 
Home | Forums | Videos | Advertise | Certifications | Downloads | Blogs | Interviews | Jobs | Beginners | Training
 | Consulting  
Submit an Article Submit a Blog 
 Jump to
Skip Navigation Links
TechnologyExpand Technology
WebsiteExpand Website
Team Foundation Server Hosting
Search :       Advanced Search »
Home » Windows Forms C# » Developing MDI Applications in C#

Developing MDI Applications in C#

In this article, I'll explain how to write MDI applications using C# and Windows Forms.

Author Rank :
Page Views : 203552
Downloads : 0
Rating :
 Rate it
Level : Beginner
   Print Read/Post comments Post a comment  Similar Articles  
   Email to a friend  Bookmark  Author's other articles  
 
Team Foundation Server Hosting
Become a Sponsor
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
 Tag Cloud
 Latest Jobs
More ... 
 Latest Interview Questions
More ... 

Introduction

In this article, I will explain basics of Multiple Document Interface (MDI) applications. MDI applications let you to show multiple documents at the same time, with every document displayed in its individual window.

Creating MDI Parent Forms

The base of a Multiple Document Interface (MDI) is the MDI parent form. This is the form that holds the MDI child windows, which are all the "sub-windows" in which the client work together with the MDI application.

To Create MDI Parent Forms:

Create a new form and add the code.

this.IsMDIContainer = true;

This assign the form as an MDI container for child windows.

Creating MDI Child Forms

An vital constituent of Multiple Document Interface (MDI) Applications is the MDI child forms, as these are the main windows for client interaction.

To Create MDI Child Forms:

Form frmchild=new Form();
frmchild.MDIParent=
this;
frmchild.Show();

Determining the Active MDI Child:

In a number of circumstance, we desire to give a command that operates on the control with the focus on the at present active child form.

For the reason that an application can have many instances of the same child form, the process wants to be acquainted with which form to use. To specify this, use the ActiveForm property of an MDI Form, which returns the child form that has the focus.

In any case one MDI child form must be loaded and visible when you access the ActiveForm property, or an error is returned.

Arranging Child Forms:

Frequently, applications will have menu commands for actions such as Tile, Cascade, and Arrange, with concerning to the open MDI child forms. One can use the LayoutMDI method with the MDILayout enumeration to rearrange the child forms in an MDI parent form.

The MDILayout enumeration can be set to four different values, which will display child forms as cascading, as horizontally or vertically. Often, these methods are used as the event handlers called by a menu item's Click event. In this way, a menu item with the text "Cascade Windows" can have the desired effect on the MDI child windows.

In the example below, the event handler for the Click event for the Cascade menu item sets the MDILayout enumeration to Cascade for the child windows of the MDI Parent form.

Example:

using System;
using System.ComponentModel;
using System.WinForms;
using System.Drawing;
public class MDI :Form
{
private MainMenu mainMenu;
private int Count=0;
public MDI()
{
this.IsMDIContainer=true;
this.Text="MDI Demo";
mainMenu =
new MainMenu();
MenuItem File = mainMenu.MenuItems.Add("&File");
File.MenuItems.Add(
new MenuItem("&New",new EventHandler this.FileNew_clicked),Shortcut.CtrlN));
File.MenuItems.Add(
new MenuItem("&Active Child",new EventHandler this.FindActive_clicked),Shortcut.CtrlA));
File.MenuItems.Add(
new MenuItem("-"));
File.MenuItems.Add(
new MenuItem("&Exit",new EventHandler this.FileExit_clicked),Shortcut.CtrlX));
MenuItem Arrange = mainMenu.MenuItems.Add("&Arrange");
Arrange.MenuItems.Add(
new MenuItem("&Cascade",new EventHandler this.Cascade_clicked),Shortcut.F1));
Arrange.MenuItems.Add(
new MenuItem("&Horizontal",new EventHandler this.Horizontal_clicked),Shortcut.F2));
Arrange.MenuItems.Add(
new MenuItem("&Vertical",new EventHandler this.Vertical_clicked),Shortcut.F3));
this.Menu=mainMenu;
mainMenu.GetForm().BackColor = Color.Indigo ;
}
private void FileExit_clicked(object sender, EventArgs e)
{
this.Close();
}
private void FindActive_clicked(object sender, EventArgs e)
{
MessageBox.Show(
this.ActiveMDIChild.Text,"MDI FORM",MessageBox.IconInformation);
}
private void FileNew_clicked(object sender, EventArgs e)
{
Form frmchild=
new Form();
frmchild.MDIParent=
this;
frmchild.Show();
frmchild.Text="Child Form" + Count.ToString();
Count++;
}
private void pop_Clicked(object sender, EventArgs e)
{
MessageBox.Show("Popupmenu","MENU_CREATION",MessageBox.IconInformation);
}
private void Cascade_clicked(object sender, EventArgs e)
{
this.LayoutMDI(MDILayout.Cascade );
}
private void Horizontal_clicked(object sender, EventArgs e)
{
this.LayoutMDI(MDILayout.TileHorizontal);
}
private void Vertical_clicked(object sender, EventArgs e)
{
this.LayoutMDI(MDILayout.TileVertical);
}
public static void Main(string[] args)
{
Application.Run(
new MDI());
}
}

Output:



Comment Request!
Thank you for reading this post. Please post your feedback, question, or comments about this post Here.
Login to add your contents and source code to this article
 [Top] Rate this article
 
 About the author
 
G Gnana Arun Ganesh
G.GNANA ARUN GANESH, an ECE graduate (1997-2001) seeking a profession in either Software or Hardware Company. During Campus interview selected as a Software Engineer at GREEN MICRO SYSTEMS Chennai, a German collaboration company. Due to down stream in software market they have cancelled the offer. His skills includes VB, COM/DCOM, ASP, VB.NET, C# and Embedded systems. He is also a writer of numerous articles for many technical Web sites.
Looking for C# Consulting?
C# Consulting is founded in 2002 by the founders of C# Corner. Unlike a traditional consulting company, our consultants are well-known experts in .NET and many of them are MVPs, authors, and trainers. We specialize in Microsoft .NET development and utilize Agile Development and Extreme Programming practices to provide fast pace quick turnaround results. Our software development model is a mix of Agile Development, traditional SDLC, and Waterfall models.
Click here to learn more about C# Consulting.
 
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
Discover the Top 5 .NET Memory Management Fundamentals
To write the best .NET code, you need to know exactly how the .NET framework really manages memory. Ricky Leeks presents the Top 5 fundamental facts of .NET memory management. Learn more.
Nevron Chart for .NET 2010.1 Now Available
The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
ASP.NET 4 Hosting
Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites – Click Here!
 
 Post a Feedback, Comment, or Question about this article
Subject:
Comment:
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
 Comments
I have made simple MDI but in a MDI program how to open an exe file in a child? by Syed Arbab On July 25, 2009

In a MDI program how to open an exe file in a child?

 I have made a program which is of MDI, but I want to open exe file in a child rather than child form or MDIParent. As in my coding in program.cs I have written Application.Run(new MDIParent1()); // to open Parent form Or I have written Application.Run(new form()); // to open a form But as I said I want exe file to open whenever I click new on MDIPARENT form, How can I do it? 

Reply | Email | Modify 
MDI Apps. by Jose On March 5, 2010

This is my question : How about if I have a button(btn1)  in Childform0, on the btn1_click event Iwant to open a new form but I want to keep that form under the MDI parent form? it is possible?

Reply | Email | Modify 
Re: MDI Apps. by gabriel On July 23, 2011
Hi! I think this is the solution for your problem http://blogcsharp.com/2011/03/c-general/basic-mdi-app/
Reply | Email | Modify 
MDI bg color by Ben On November 6, 2010

Hi,
I found that  the MDI parent interface will be in  gray and  can't change the bg color when I set IsMdiContainer property to true ? Can you give me some advise?Thanks

Reply | Email | Modify 
MDI Applications by gabriel On July 23, 2011
Hi! What do you say about this sample: http://blogcsharp.com/2011/03/c-general/basic-mdi-app/
Reply | Email | Modify 
6 Months Free & No Setup Fees ASP.NET Hosting!
 © 2012  contents copyright of their authors. Rest everything copyright Mindcracker. All rights reserved.