Multiple Document Interface (MDI) form

Multiple Document Interface (MDI) form –

MDI form closely resembles a standard form with one major difference – the client area of an MDI form acts as a kind of container for other forms. It means that an MDI form also called an MDI parent form, can display MDI children in it, which is how the multiple document interfaces work.

Creating MDI Applications :

MDI forms are useful when the users want to open more than one document at a time.


"http://1.bp.blogspot.com/_UeWJDdIKSOo/Spa9zfoP9WI/AAAAAAAAAFg/sW9vXHT354A/s320/1.jpg"














"http://3.bp.blogspot.com/_UeWJDdIKSOo/Spa-E_FjPuI/AAAAAAAAAFo/nf1bQ6j0nR4/s320/2.jpg"











Creating MDI Child Windows in Code :

For adding MDI child windows into our MDI parent form, first I’ll create a form class MDIChild and then i’ll create MDI child windows by creating and displaying a new object of the class each time the user clicks on New Option in File Menu bar in application. To make that new form object a child window of the MDI parent, MDIparent, we have to set its MdiParent property to the main window which also sets its IsMdiChild property to True. For working with number of child windows we need to store them in a array of forms.

Steps :

1. Add RichtextBox to MDIChild (to second form)

2. Set Dock property of Richtextbox to fill by clicking on the square shaped button in the properties window



"http://2.bp.blogspot.com/_UeWJDdIKSOo/Spa-b6XCvdI/AAAAAAAAAFw/ymFWXtSCiIA/s320/3.jpg"










3. Add following code in MDIParent.cs

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

namespace MyWinForms

{

public partial class MDIParent : Form

{

int NumberofForms = 0;

MDIChild[] Forms = new MDIChild[11];

public MDIParent()

{

InitializeComponent();

}

private void MDIParent_Load(object sender, EventArgs e)

{

}

private void newToolStripMenuItem_Click(object sender, EventArgs e)

{

NumberofForms +=1;

Forms[NumberofForms] = new MDIChild();

Forms[NumberofForms].Text = "Document" + Convert.ToString(NumberofForms);

Forms[NumberofForms].MdiParent = this;

Forms[NumberofForms].Show();

}

}

}

4. Finally Run the application. Click on File -> New


"http://4.bp.blogspot.com/_UeWJDdIKSOo/Spa-4GKz78I/AAAAAAAAAF4/LSMr-2wsGmo/s320/4.jpg"









"http://1.bp.blogspot.com/_UeWJDdIKSOo/Spa_IMmgtJI/AAAAAAAAAGA/gLn1Cp9tvC8/s320/5.jpg"



Reference: http://angeldeeps.blogspot.com/2009/08/multiple-document-interface-mdi-form.html


Comments

Guest Author: Blessing09 Dec 2011

Enlightening the world, one helpful article at a time.



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: