Arrange Child form : MDI « GUI Windows Forms « C# / CSharp Tutorial






Arrange Child form
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

public class MDIFormArrange : System.Windows.Forms.Form
{
  private System.Windows.Forms.MainMenu mainMenu1;
  private System.Windows.Forms.MenuItem mnuFile;
  private System.Windows.Forms.MenuItem mnuFileExit;
  private System.Windows.Forms.MenuItem mnuWindow;
  private System.Windows.Forms.MenuItem mnuArrange;
  private System.Windows.Forms.MenuItem mnuArrangeCascade;
  private System.Windows.Forms.MenuItem mnuArrangeVert;
  private System.Windows.Forms.MenuItem mnuArrangeHorizontal;
  private System.Windows.Forms.MenuItem mnuFileNew;

  private System.ComponentModel.Container components = null;

  public MDIFormArrange()
  {
    InitializeComponent();
  }

  protected override void Dispose( bool disposing )
  {
    if( disposing )
    {
      if (components != null) 
      {
        components.Dispose();
      }
    }
    base.Dispose( disposing );
  }

  private void InitializeComponent()
  {
    this.mainMenu1 = new System.Windows.Forms.MainMenu();
    this.mnuFile = new System.Windows.Forms.MenuItem();
    this.mnuFileNew = new System.Windows.Forms.MenuItem();
    this.mnuFileExit = new System.Windows.Forms.MenuItem();
    this.mnuWindow = new System.Windows.Forms.MenuItem();
    this.mnuArrange = new System.Windows.Forms.MenuItem();
    this.mnuArrangeCascade = new System.Windows.Forms.MenuItem();
    this.mnuArrangeVert = new System.Windows.Forms.MenuItem();
    this.mnuArrangeHorizontal = new System.Windows.Forms.MenuItem();
    // 
    this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
                                          this.mnuFile,
                                          this.mnuWindow,
                                          this.mnuArrange});
    // 
    this.mnuFile.Index = 0;
    this.mnuFile.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
                                        this.mnuFileNew,
                                        this.mnuFileExit});
    this.mnuFile.Text = "&File";
    // 
    this.mnuFileNew.Index = 0;
    this.mnuFileNew.Text = "&New";
    this.mnuFileNew.Click += new System.EventHandler(this.mnuFileNew_Click);
    // 
    this.mnuFileExit.Index = 1;
    this.mnuFileExit.Text = "E&xit";
    this.mnuFileExit.Click += new System.EventHandler(this.mnuFileExit_Click);
    // 
    this.mnuWindow.Index = 1;
    this.mnuWindow.MdiList = true;
    this.mnuWindow.Text = "&Window";
    // 
    this.mnuArrange.Index = 2;
    this.mnuArrange.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
                                           this.mnuArrangeCascade,
                                           this.mnuArrangeVert,
                                           this.mnuArrangeHorizontal});
    this.mnuArrange.Text = "&Arrange Window";
    // 
    this.mnuArrangeCascade.Index = 0;
    this.mnuArrangeCascade.Text = "&Cascade";
    this.mnuArrangeCascade.Click += new System.EventHandler(this.mnuArrangeCascade_Click);
    // 
    this.mnuArrangeVert.Index = 1;
    this.mnuArrangeVert.Text = "&Vertical";
    this.mnuArrangeVert.Click += new System.EventHandler(this.mnuArrangeVert_Click);
    // 
    this.mnuArrangeHorizontal.Index = 2;
    this.mnuArrangeHorizontal.Text = "&Horizontal";
    this.mnuArrangeHorizontal.Click += new System.EventHandler(this.mnuArrangeHorizontal_Click);
    // 
    this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
    this.ClientSize = new System.Drawing.Size(292, 269);
    this.IsMdiContainer = true;
    this.Menu = this.mainMenu1;
    this.Name = "MDIFormArrange";
    this.Text = "The MDI Application";

  }

  [STAThread]
  static void Main() 
  {
    Application.Run(new MDIFormArrange());
  }

  private void mnuFileExit_Click(object sender, System.EventArgs e)
  { 
      this.Close(); 
  }

  private void mnuArrangeCascade_Click(object sender, System.EventArgs e)
  { 
      LayoutMdi(MdiLayout.Cascade); 
  }

  private void mnuArrangeVert_Click(object sender, System.EventArgs e)
  { 
      LayoutMdi(MdiLayout.TileVertical); 
  }

  private void mnuArrangeHorizontal_Click(object sender, System.EventArgs e)
  { 
      LayoutMdi(MdiLayout.TileHorizontal); 
  }

  private void mnuFileNew_Click(object sender, System.EventArgs e)
  {
    MDIChildForm newChild = new MDIChildForm();

    newChild.MdiParent = this;

    newChild.Show();    
  }
}
public class MDIChildForm : System.Windows.Forms.Form
{
  private System.ComponentModel.Container components = null;

  public MDIChildForm()
  {
    InitializeComponent();

  }

  protected override void Dispose( bool disposing )
  {
    if( disposing )
    {
      if(components != null)
      {
        components.Dispose();
      }
    }
    base.Dispose( disposing );
  }

  private void InitializeComponent()
  {
    this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
    this.ClientSize = new System.Drawing.Size(292, 269);
  }
}








23.6.MDI
23.6.1.Is a form Mdi Container
23.6.2.Set MdiParent
23.6.3.MDI children form backgroundMDI children form background
23.6.4.Arrange Child formArrange Child form