Csharp/C Sharp/GUI Windows Form/MDI — различия между версиями

Материал из .Net Framework эксперт
Перейти к: навигация, поиск
м (1 версия)
 
(нет различий)

Текущая версия на 11:33, 26 мая 2010

Form Ownership

/*
User Interfaces in C#: Windows Forms and Custom Controls
by Matthew MacDonald
Publisher: Apress
ISBN: 1590590457
*/
using System;
using System.Drawing;
using System.Collections;
using System.ruponentModel;
using System.Windows.Forms;
namespace FormOwnership
{
    /// <summary>
    /// Summary description for Owner.
    /// </summary>
    public class Owner : System.Windows.Forms.Form
    {
        internal System.Windows.Forms.Button cmdReleaseOwnership;
        internal System.Windows.Forms.Button cmdAddOwnership;
        private System.Windows.Forms.Label label1;
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ruponentModel.Container components = null;
        public Owner()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();
            //
            // TODO: Add any constructor code after InitializeComponent call
            //
        }
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose( bool disposing )
        {
            if( disposing )
            {
                if(components != null)
                {
                    components.Dispose();
                }
            }
            base.Dispose( disposing );
        }
        #region Windows Form Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.cmdReleaseOwnership = new System.Windows.Forms.Button();
            this.cmdAddOwnership = new System.Windows.Forms.Button();
            this.label1 = new System.Windows.Forms.Label();
            this.SuspendLayout();
            // 
            // cmdReleaseOwnership
            // 
            this.cmdReleaseOwnership.FlatStyle = System.Windows.Forms.FlatStyle.System;
            this.cmdReleaseOwnership.Location = new System.Drawing.Point(152, 196);
            this.cmdReleaseOwnership.Name = "cmdReleaseOwnership";
            this.cmdReleaseOwnership.Size = new System.Drawing.Size(128, 32);
            this.cmdReleaseOwnership.TabIndex = 3;
            this.cmdReleaseOwnership.Text = "Remove Ownership";
            this.cmdReleaseOwnership.Click += new System.EventHandler(this.cmdReleaseOwnership_Click);
            // 
            // cmdAddOwnership
            // 
            this.cmdAddOwnership.FlatStyle = System.Windows.Forms.FlatStyle.System;
            this.cmdAddOwnership.Location = new System.Drawing.Point(16, 196);
            this.cmdAddOwnership.Name = "cmdAddOwnership";
            this.cmdAddOwnership.Size = new System.Drawing.Size(120, 32);
            this.cmdAddOwnership.TabIndex = 2;
            this.cmdAddOwnership.Text = "Set Ownership";
            this.cmdAddOwnership.Click += new System.EventHandler(this.cmdAddOwnership_Click);
            // 
            // label1
            // 
            this.label1.Location = new System.Drawing.Point(40, 36);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(216, 80);
            this.label1.TabIndex = 4;
            this.label1.Text = "To test form ownership, try minimizing this form when the second form is owned. T" +
                "hen try, minimizing it when the second form is not owned.";
            // 
            // Owner
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 14);
            this.ClientSize = new System.Drawing.Size(292, 242);
            this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                          this.label1,
                                                                          this.cmdReleaseOwnership,
                                                                          this.cmdAddOwnership});
            this.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
            this.Name = "Owner";
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "Owner";
            this.Load += new System.EventHandler(this.Owner_Load);
            this.ResumeLayout(false);
        }
        #endregion
        private OwnedForm frmOwned = new OwnedForm();
        private void Owner_Load(object sender, System.EventArgs e)
        {
            this.Show();
            frmOwned.Show();
        }
        private void cmdAddOwnership_Click(object sender, System.EventArgs e)
        {
            this.AddOwnedForm(frmOwned);
            frmOwned.lblState.Text = "I"m Owned";
        }
        private void cmdReleaseOwnership_Click(object sender, System.EventArgs e)
        {
            this.RemoveOwnedForm(frmOwned);
            frmOwned.lblState.Text = "I"m Free!";
        }
        [STAThread]
        static void Main() 
        {
            Application.Run(new Owner());
        }
    }
    /// <summary>
    /// Summary description for OwnedForm.
    /// </summary>
    public class OwnedForm : System.Windows.Forms.Form
    {
        public System.Windows.Forms.Label lblState;
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ruponentModel.Container components = null;
        public OwnedForm()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();
            //
            // TODO: Add any constructor code after InitializeComponent call
            //
        }
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose( bool disposing )
        {
            if( disposing )
            {
                if(components != null)
                {
                    components.Dispose();
                }
            }
            base.Dispose( disposing );
        }
        #region Windows Form Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.lblState = new System.Windows.Forms.Label();
            this.SuspendLayout();
            // 
            // lblState
            // 
            this.lblState.Location = new System.Drawing.Point(8, 8);
            this.lblState.Name = "lblState";
            this.lblState.Size = new System.Drawing.Size(184, 56);
            this.lblState.TabIndex = 1;
            // 
            // OwnedForm
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 14);
            this.ClientSize = new System.Drawing.Size(208, 78);
            this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                          this.lblState});
            this.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
            this.Name = "OwnedForm";
            this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
            this.Text = "OwnedForm";
            this.ResumeLayout(false);
        }
        #endregion
    }

}


Maximized MDI window at startup

using System;
using System.Drawing;
using System.Collections;
using System.ruponentModel;
using System.Windows.Forms;
using System.Data;
namespace MdiBasic
{
  public class frmContainer : System.Windows.Forms.Form
  {
    private System.ruponentModel.Container components = null;
    public frmContainer()
    {
      InitializeComponent();
            MdiBasic.frmChild child = new MdiBasic.frmChild(this);
            child.Show();
        }
    private void InitializeComponent()
    {
         this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
         this.ClientSize = new System.Drawing.Size(292, 273);
         this.IsMdiContainer = true;
         this.Name = "frmContainer";
         this.Text = "MDI Basic";
         this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
        }
    [STAThread]
    static void Main() 
    {
      Application.Run(new frmContainer());
    }
  }
  public class frmChild : System.Windows.Forms.Form
  {
    private System.ruponentModel.Container components = null;
        public frmChild(MdiBasic.frmContainer parent)
    {
      InitializeComponent();
            this.MdiParent = parent;
        }
    private void InitializeComponent()
    {
      this.ruponents = new System.ruponentModel.Container();
      this.Size = new System.Drawing.Size(300,300);
      this.Text = "frmChild";
    }
  }
}


MDI and Dock

/*
User Interfaces in C#: Windows Forms and Custom Controls
by Matthew MacDonald
Publisher: Apress
ISBN: 1590590457
*/
using System;
using System.Drawing;
using System.Collections;
using System.ruponentModel;
using System.Windows.Forms;
using System.Data;
using System.Drawing.Drawing2D;
namespace DockingWindows
{
    /// <summary>
    /// Summary description for Form1.
    /// </summary>
    public class MDIMain : System.Windows.Forms.Form
    {
        internal System.Windows.Forms.Panel pnlDock;
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ruponentModel.Container components = null;
        public MDIMain()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();
            //
            // TODO: Add any constructor code after InitializeComponent call
            //
        }
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose( bool disposing )
        {
            if( disposing )
            {
                if (components != null) 
                {
                    components.Dispose();
                }
            }
            base.Dispose( disposing );
        }
        #region Windows Form Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.pnlDock = new System.Windows.Forms.Panel();
            this.SuspendLayout();
            // 
            // pnlDock
            // 
            this.pnlDock.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
                | System.Windows.Forms.AnchorStyles.Left);
            this.pnlDock.BackColor = System.Drawing.SystemColors.AppWorkspace;
            this.pnlDock.Name = "pnlDock";
            this.pnlDock.Size = new System.Drawing.Size(148, 302);
            this.pnlDock.TabIndex = 2;
            this.pnlDock.Visible = false;
            this.pnlDock.Paint += new System.Windows.Forms.PaintEventHandler(this.pnlDock_Paint);
            // 
            // MDIMain
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(534, 304);
            this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                          this.pnlDock});
            this.IsMdiContainer = true;
            this.Name = "MDIMain";
            this.Text = "Form1";
            this.Load += new System.EventHandler(this.Form1_Load);
            this.ResumeLayout(false);
        }
        #endregion
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main() 
        {
            Application.Run(new MDIMain());
        }
        private void Form1_Load(object sender, System.EventArgs e)
        {
            Floater frmFloat = new Floater();
            frmFloat.Owner = this;
            frmFloat.Show();
        }

        public bool DrawDockRectangle
        {
            get
            {
                return pnlDock.Visible;
            }
            set
            {
                pnlDock.Visible = value;
            }
        }
        public void AddToDock(Form frm)
        {
            // Allow the form to be contained in a container control.
            frm.TopLevel = false;
            pnlDock.Controls.Add(frm);
            // Don"t let the form be dragged off.
            frm.WindowState = FormWindowState.Maximized;
        }
        private void pnlDock_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
        {
            HatchBrush dockCueBrush = new HatchBrush(HatchStyle.LightDownwardDiagonal, 
                Color.White, Color.Gray);
            Pen dockCuePen = new Pen(dockCueBrush, 10);
            e.Graphics.DrawRectangle(dockCuePen, 
                new Rectangle(0, 0, pnlDock.Width, pnlDock.Height));
        }
    }
    /// <summary>
    /// Summary description for Floater.
    /// </summary>
    public class Floater : System.Windows.Forms.Form
    {
        internal System.Windows.Forms.PictureBox PictureBox2;
        internal System.Windows.Forms.Button Button3;
        internal System.Windows.Forms.Button Button2;
        internal System.Windows.Forms.Button Button1;
        internal System.Windows.Forms.Timer tmrDock;
        private System.ruponentModel.IContainer components;
        public Floater()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();
            //
            // TODO: Add any constructor code after InitializeComponent call
            //
        }
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose( bool disposing )
        {
            if( disposing )
            {
                if(components != null)
                {
                    components.Dispose();
                }
            }
            base.Dispose( disposing );
        }
        #region Windows Form Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.ruponents = new System.ruponentModel.Container();
            this.PictureBox2 = new System.Windows.Forms.PictureBox();
            this.Button3 = new System.Windows.Forms.Button();
            this.Button2 = new System.Windows.Forms.Button();
            this.Button1 = new System.Windows.Forms.Button();
            this.tmrDock = new System.Windows.Forms.Timer(this.ruponents);
            this.SuspendLayout();
            // 
            // PictureBox2
            // 
            this.PictureBox2.Anchor = (((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
                | System.Windows.Forms.AnchorStyles.Left) 
                | System.Windows.Forms.AnchorStyles.Right);
            this.PictureBox2.Location = new System.Drawing.Point(1, -3);
            this.PictureBox2.Name = "PictureBox2";
            this.PictureBox2.Size = new System.Drawing.Size(134, 172);
            this.PictureBox2.TabIndex = 2;
            this.PictureBox2.TabStop = false;
            
            // 
            // Button3
            // 
            this.Button3.FlatStyle = System.Windows.Forms.FlatStyle.System;
            this.Button3.Location = new System.Drawing.Point(14, 56);
            this.Button3.Name = "Button3";
            this.Button3.Size = new System.Drawing.Size(108, 20);
            this.Button3.TabIndex = 7;
            this.Button3.Text = "Controls";
            // 
            // Button2
            // 
            this.Button2.FlatStyle = System.Windows.Forms.FlatStyle.System;
            this.Button2.Location = new System.Drawing.Point(14, 36);
            this.Button2.Name = "Button2";
            this.Button2.Size = new System.Drawing.Size(108, 20);
            this.Button2.TabIndex = 6;
            this.Button2.Text = "Dockable";
            // 
            // Button1
            // 
            this.Button1.FlatStyle = System.Windows.Forms.FlatStyle.System;
            this.Button1.Location = new System.Drawing.Point(14, 16);
            this.Button1.Name = "Button1";
            this.Button1.Size = new System.Drawing.Size(108, 20);
            this.Button1.TabIndex = 5;
            this.Button1.Text = "Sample";
            // 
            // tmrDock
            // 
            this.tmrDock.Interval = 10;
            this.tmrDock.Tick += new System.EventHandler(this.tmrDock_Tick);
            // 
            // Floater
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 14);
            this.ClientSize = new System.Drawing.Size(136, 166);
            this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                          this.Button3,
                                                                          this.Button2,
                                                                          this.Button1,
                                                                          this.PictureBox2});
            this.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
            this.Name = "Floater";
            this.Text = "Floater";
            this.Move += new System.EventHandler(this.Floater_Move);
            this.ResumeLayout(false);
        }
        #endregion

        private Point dockTestAt;
        private void Floater_Move(object sender, System.EventArgs e)
        {
            // Determine the current location in parent form coordinates.
            Point mouseAt = this.Owner.PointToClient(this.Location);
            // Determine if the floated is close enough to dock.
            if (mouseAt.X < 5 && mouseAt.X > -5)
            {
                if ((Control.MouseButtons & MouseButtons.Left) == MouseButtons.Left)
                {
                    dockTestAt = mouseAt;
                    // Show the dock focus rectangle.
                    ((MDIMain)this.Owner).DrawDockRectangle = true;
                    // Reset the timer to poll for the MouseUp event.
                    tmrDock.Enabled = false;
                    tmrDock.Enabled = true;
                }
            }
        }
        private void tmrDock_Tick(object sender, System.EventArgs e)
        {
            if (dockTestAt.X == this.Owner.PointToClient(this.Location).X 
                && dockTestAt.Y == this.Owner.PointToClient(this.Location).Y)
            {
                if (Control.MouseButtons == MouseButtons.None)
                {
                    // Dock in place.
                    tmrDock.Enabled = false;
                    ((MDIMain)this.Owner).AddToDock(this);
                }
            }
            else
            {
                // Mouse has moved. Disable this dock attempt.
                tmrDock.Enabled = false;
                ((MDIMain)this.Owner).DrawDockRectangle = false;
            }
        }

    }

}


MDI Basics

/*
User Interfaces in C#: Windows Forms and Custom Controls
by Matthew MacDonald
Publisher: Apress
ISBN: 1590590457
*/
using System;
using System.Drawing;
using System.Collections;
using System.ruponentModel;
using System.Windows.Forms;
namespace MDIBasics
{
    /// <summary>
    /// Summary description for Parent.
    /// </summary>
    public class Parent : System.Windows.Forms.Form
    {
        internal System.Windows.Forms.Button Button1;
        internal System.Windows.Forms.MainMenu MainMenu1;
        internal System.Windows.Forms.MenuItem MenuItem1;
        internal System.Windows.Forms.MenuItem MenuItem2;
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ruponentModel.Container components = null;
        public Parent()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();
            //
            // TODO: Add any constructor code after InitializeComponent call
            //
        }
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose( bool disposing )
        {
            if( disposing )
            {
                if(components != null)
                {
                    components.Dispose();
                }
            }
            base.Dispose( disposing );
        }
        #region Windows Form Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.Button1 = new System.Windows.Forms.Button();
            this.MainMenu1 = new System.Windows.Forms.MainMenu();
            this.MenuItem1 = new System.Windows.Forms.MenuItem();
            this.MenuItem2 = new System.Windows.Forms.MenuItem();
            this.SuspendLayout();
            // 
            // Button1
            // 
            this.Button1.FlatStyle = System.Windows.Forms.FlatStyle.System;
            this.Button1.Location = new System.Drawing.Point(82, 99);
            this.Button1.Name = "Button1";
            this.Button1.Size = new System.Drawing.Size(128, 68);
            this.Button1.TabIndex = 2;
            this.Button1.Text = "A Suspended Button";
            // 
            // MainMenu1
            // 
            this.MainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
                                                                                      this.MenuItem1,
                                                                                      this.MenuItem2});
            // 
            // MenuItem1
            // 
            this.MenuItem1.Index = 0;
            this.MenuItem1.Text = "File";
            // 
            // MenuItem2
            // 
            this.MenuItem2.Index = 1;
            this.MenuItem2.Text = "Help";
            // 
            // Parent
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 14);
            this.ClientSize = new System.Drawing.Size(292, 266);
            this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                          this.Button1});
            this.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
            this.IsMdiContainer = true;
            this.Menu = this.MainMenu1;
            this.Name = "Parent";
            this.Text = "Parent";
            this.Load += new System.EventHandler(this.Parent_Load);
            this.ResumeLayout(false);
        }
        #endregion
        [STAThread]
        static void Main() 
        {
            Application.Run(new Parent());
        }
        private void Parent_Load(object sender, System.EventArgs e)
        {
            Child frmChild = new Child();
            frmChild.MdiParent = this;
            frmChild.Show();
        }
    }
    /// <summary>
    /// Summary description for Child.
    /// </summary>
    public class Child : System.Windows.Forms.Form
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ruponentModel.Container components = null;
        public Child()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();
            //
            // TODO: Add any constructor code after InitializeComponent call
            //
        }
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose( bool disposing )
        {
            if( disposing )
            {
                if(components != null)
                {
                    components.Dispose();
                }
            }
            base.Dispose( disposing );
        }
        #region Windows Form Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            // 
            // Child
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(236, 94);
            this.Name = "Child";
            this.Text = "Child";
        }
        #endregion
    }

}


MDI form

/*
User Interfaces in C#: Windows Forms and Custom Controls
by Matthew MacDonald
Publisher: Apress
ISBN: 1590590457
*/
using System;
using System.Drawing;
using System.Collections;
using System.ruponentModel;
using System.Windows.Forms;
using System.Data;
namespace ImpossibleAPI
{
    
    public class Global
    {
        public static Form1 Main1 = new Form1();
        public static Form1 Main2 = new Form1();
        public static Form2 Child = new Form2();                                
                                                                                
        [STAThread]
        public static void Main() 
        {
            Main1.Text = "Parent 2";
            Main2.Text = "Parent 1";
            Main1.Show();
            Main2.Show();
            
            Child.MdiParent = Main2;
            Child.Show();
            System.Windows.Forms.Application.Run();
        }
        
    }
    /// <summary>
    /// Summary description for Form2.
    /// </summary>
    public class Form2 : System.Windows.Forms.Form
    {
        internal System.Windows.Forms.Button Button3;
        internal System.Windows.Forms.Button Button2;
        internal System.Windows.Forms.Button Button1;
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ruponentModel.Container components = null;
        public Form2()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();
            //
            // TODO: Add any constructor code after InitializeComponent call
            //
        }
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose( bool disposing )
        {
            if( disposing )
            {
                if(components != null)
                {
                    components.Dispose();
                }
            }
            base.Dispose( disposing );
        }
        #region Windows Form Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.Button3 = new System.Windows.Forms.Button();
            this.Button2 = new System.Windows.Forms.Button();
            this.Button1 = new System.Windows.Forms.Button();
            this.SuspendLayout();
            // 
            // Button3
            // 
            this.Button3.Location = new System.Drawing.Point(124, 60);
            this.Button3.Name = "Button3";
            this.Button3.Size = new System.Drawing.Size(88, 32);
            this.Button3.TabIndex = 5;
            this.Button3.Text = "Become Child of Parent2";
            this.Button3.Click += new System.EventHandler(this.Button3_Click);
            // 
            // Button2
            // 
            this.Button2.Location = new System.Drawing.Point(16, 60);
            this.Button2.Name = "Button2";
            this.Button2.Size = new System.Drawing.Size(88, 32);
            this.Button2.TabIndex = 4;
            this.Button2.Text = "Become Child of Parent1";
            this.Button2.Click += new System.EventHandler(this.Button2_Click);
            // 
            // Button1
            // 
            this.Button1.Location = new System.Drawing.Point(16, 16);
            this.Button1.Name = "Button1";
            this.Button1.Size = new System.Drawing.Size(88, 32);
            this.Button1.TabIndex = 3;
            this.Button1.Text = "Become Parent";
            this.Button1.Click += new System.EventHandler(this.Button1_Click);
            // 
            // Form2
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 14);
            this.ClientSize = new System.Drawing.Size(292, 150);
            this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                          this.Button3,
                                                                          this.Button2,
                                                                          this.Button1});
            this.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
            this.Name = "Form2";
            this.Text = "Form2";
            this.ResumeLayout(false);
        }
        #endregion
        private void Button1_Click(object sender, System.EventArgs e)
        {
            this.Hide();
            this.MdiParent = null;
            this.IsMdiContainer = true;
            this.Show();
        }
        private void Button2_Click(object sender, System.EventArgs e)
        {
            this.Hide();
            this.IsMdiContainer = false;
            this.MdiParent = Global.Main2;
            this.Show();
        }
        private void Button3_Click(object sender, System.EventArgs e)
        {
            this.Hide();
            this.IsMdiContainer = false;
            this.MdiParent = Global.Main1;
            this.Show();
        }
    }
    /// <summary>
    /// Summary description for Form1.
    /// </summary>
    public class Form1 : System.Windows.Forms.Form
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ruponentModel.Container components = null;
        public Form1()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();
            //
            // TODO: Add any constructor code after InitializeComponent call
            //
        }
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose( bool disposing )
        {
            if( disposing )
            {
                if (components != null) 
                {
                    components.Dispose();
                }
            }
            base.Dispose( disposing );
        }
        #region Windows Form Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            // 
            // Form1
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(464, 370);
            this.IsMdiContainer = true;
            this.Name = "Form1";
            this.Text = "Form1";
            this.Closing += new System.ruponentModel.CancelEventHandler(this.Form1_Closing);
            this.Load += new System.EventHandler(this.Form1_Load);
        }
        #endregion
        private void Form1_Load(object sender, System.EventArgs e)
        {
        
        }
        private void Form1_Closing(object sender, System.ruponentModel.CancelEventArgs e)
        {
            Application.Exit();
        }
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
    }

}


MdiLayout.Cascade

using System;
using System.Collections.Generic;
using System.ruponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
public class Form1 : Form
{
      private System.Windows.Forms.MenuStrip menuStrip1;
      private System.Windows.Forms.ToolStripMenuItem fileToolStripMenuItem;
      private System.Windows.Forms.ToolStripMenuItem newToolStripMenuItem;
      private System.Windows.Forms.ToolStripMenuItem exitToolStripMenuItem;
      private System.Windows.Forms.ToolStripMenuItem child1ToolStripMenuItem;
      private System.Windows.Forms.ToolStripMenuItem windowToolStripMenuItem;
      private System.Windows.Forms.ToolStripMenuItem cascadeToolStripMenuItem;
      private System.Windows.Forms.ToolStripMenuItem tileHorizontalToolStripMenuItem;
      private System.Windows.Forms.ToolStripMenuItem tileVerticalToolStripMenuItem;
      private System.Windows.Forms.ToolStripSeparator toolStripSeparator1;
      
      public Form1() {
        InitializeComponent();
      }
      private void child1ToolStripMenuItem_Click(object sender, EventArgs e ){
        ChildForm formChild = new ChildForm("Child", "winter.jpg" );
        formChild.MdiParent = this;
        formChild.Show();
     }
     private void cascadeToolStripMenuItem_Click(object sender, EventArgs e ) {
       this.LayoutMdi( MdiLayout.Cascade );
     } 
     private void tileHorizontalToolStripMenuItem_Click(object sender, EventArgs e ) {
       this.LayoutMdi( MdiLayout.TileHorizontal );
     }
     private void tileVerticalToolStripMenuItem_Click(object sender, EventArgs e ) {
       this.LayoutMdi( MdiLayout.TileVertical );
     }
     private void InitializeComponent() {
         this.menuStrip1 = new System.Windows.Forms.MenuStrip();
         this.fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
         this.newToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
         this.child1ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
         this.exitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
         this.windowToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
         this.cascadeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
         this.tileHorizontalToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
         this.tileVerticalToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
         this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
         this.menuStrip1.SuspendLayout();
         this.SuspendLayout();
         // 
         // menuStrip1
         // 
         this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.fileToolStripMenuItem,
            this.windowToolStripMenuItem});
         this.menuStrip1.Location = new System.Drawing.Point(0, 0);
         this.menuStrip1.MdiWindowListItem = this.windowToolStripMenuItem;
         this.menuStrip1.Name = "menuStrip1";
         this.menuStrip1.Size = new System.Drawing.Size(353, 24);
         this.menuStrip1.TabIndex = 1;
         this.menuStrip1.Text = "menuStrip1";
         // 
         // fileToolStripMenuItem
         // 
         this.fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.newToolStripMenuItem,
            this.exitToolStripMenuItem});
         this.fileToolStripMenuItem.Name = "fileToolStripMenuItem";
         this.fileToolStripMenuItem.Text = "File";
         // 
         // newToolStripMenuItem
         // 
         this.newToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.child1ToolStripMenuItem});
         this.newToolStripMenuItem.Name = "newToolStripMenuItem";
         this.newToolStripMenuItem.Text = "New";
         // 
         // child1ToolStripMenuItem
         // 
         this.child1ToolStripMenuItem.Name = "child1ToolStripMenuItem";
         this.child1ToolStripMenuItem.Text = "Child1";
         this.child1ToolStripMenuItem.Click += new System.EventHandler(this.child1ToolStripMenuItem_Click);
         // 
         // exitToolStripMenuItem
         // 
         this.exitToolStripMenuItem.Name = "exitToolStripMenuItem";
         this.exitToolStripMenuItem.Text = "Exit";
         // 
         // windowToolStripMenuItem
         // 
         this.windowToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.cascadeToolStripMenuItem,
            this.tileHorizontalToolStripMenuItem,
            this.tileVerticalToolStripMenuItem,
            this.toolStripSeparator1});
         this.windowToolStripMenuItem.Name = "windowToolStripMenuItem";
         this.windowToolStripMenuItem.Text = "Window";
         // 
         // cascadeToolStripMenuItem
         // 
         this.cascadeToolStripMenuItem.Name = "cascadeToolStripMenuItem";
         this.cascadeToolStripMenuItem.Text = "Cascade";
         this.cascadeToolStripMenuItem.Click += new System.EventHandler(this.cascadeToolStripMenuItem_Click);
         // 
         // tileHorizontalToolStripMenuItem
         // 
         this.tileHorizontalToolStripMenuItem.Name = "tileHorizontalToolStripMenuItem";
         this.tileHorizontalToolStripMenuItem.Text = "Tile Horizontal";
         this.tileHorizontalToolStripMenuItem.Click += new System.EventHandler(this.tileHorizontalToolStripMenuItem_Click);
         // 
         // tileVerticalToolStripMenuItem
         // 
         this.tileVerticalToolStripMenuItem.Name = "tileVerticalToolStripMenuItem";
         this.tileVerticalToolStripMenuItem.Text = "Tile Vertical";
         this.tileVerticalToolStripMenuItem.Click += new System.EventHandler(this.tileVerticalToolStripMenuItem_Click);
         // 
         // toolStripSeparator1
         // 
         this.toolStripSeparator1.Name = "toolStripSeparator1";
         // 
         // UsingMDIForm
         // 
         this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
         this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
         this.ClientSize = new System.Drawing.Size(353, 310);
         this.Controls.Add(this.menuStrip1);
         this.IsMdiContainer = true;
         this.MainMenuStrip = this.menuStrip1;
         this.Name = "UsingMDIForm";
         this.Text = "UsingMDI";
         this.menuStrip1.ResumeLayout(false);
         this.ResumeLayout(false);
         this.PerformLayout();
      }
    [STAThread]
    static void Main()
    {
        Application.EnableVisualStyles();
        Application.Run(new Form1());
    }
}
public class ChildForm : Form
{
   private System.Windows.Forms.PictureBox picDisplay;
   
   public ChildForm( string title, string fileName )
   {
      InitializeComponent();
      Text = title; 
      picDisplay.Image = Image.FromFile(fileName);
   }
   
   private void InitializeComponent() {
         this.picDisplay = new System.Windows.Forms.PictureBox();
         ((System.ruponentModel.ISupportInitialize)(this.picDisplay)).BeginInit();
         this.SuspendLayout();
         // 
         // picDisplay
         // 
         this.picDisplay.Location = new System.Drawing.Point(1, 7);
         this.picDisplay.Name = "picDisplay";
         this.picDisplay.Size = new System.Drawing.Size(225, 247);
         this.picDisplay.TabIndex = 0;
         this.picDisplay.TabStop = false;
         // 
         // ChildForm
         // 
         this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
         this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
         this.ClientSize = new System.Drawing.Size(227, 256);
         this.Controls.Add(this.picDisplay);
         this.Name = "ChildForm";
         this.Text = "Child";
         ((System.ruponentModel.ISupportInitialize)(this.picDisplay)).EndInit();
         this.ResumeLayout(false);
      }
}


MdiLayout.TileHorizontal

using System;
using System.Collections.Generic;
using System.ruponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
public class Form1 : Form
{
      private System.Windows.Forms.MenuStrip menuStrip1;
      private System.Windows.Forms.ToolStripMenuItem fileToolStripMenuItem;
      private System.Windows.Forms.ToolStripMenuItem newToolStripMenuItem;
      private System.Windows.Forms.ToolStripMenuItem exitToolStripMenuItem;
      private System.Windows.Forms.ToolStripMenuItem child1ToolStripMenuItem;
      private System.Windows.Forms.ToolStripMenuItem windowToolStripMenuItem;
      private System.Windows.Forms.ToolStripMenuItem cascadeToolStripMenuItem;
      private System.Windows.Forms.ToolStripMenuItem tileHorizontalToolStripMenuItem;
      private System.Windows.Forms.ToolStripMenuItem tileVerticalToolStripMenuItem;
      private System.Windows.Forms.ToolStripSeparator toolStripSeparator1;
      
      public Form1() {
        InitializeComponent();
      }
      private void child1ToolStripMenuItem_Click(object sender, EventArgs e ){
        ChildForm formChild = new ChildForm("Child", "winter.jpg" );
        formChild.MdiParent = this;
        formChild.Show();
     }
     private void cascadeToolStripMenuItem_Click(object sender, EventArgs e ) {
       this.LayoutMdi( MdiLayout.Cascade );
     } 
     private void tileHorizontalToolStripMenuItem_Click(object sender, EventArgs e ) {
       this.LayoutMdi( MdiLayout.TileHorizontal );
     }
     private void tileVerticalToolStripMenuItem_Click(object sender, EventArgs e ) {
       this.LayoutMdi( MdiLayout.TileVertical );
     }
     private void InitializeComponent() {
         this.menuStrip1 = new System.Windows.Forms.MenuStrip();
         this.fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
         this.newToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
         this.child1ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
         this.exitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
         this.windowToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
         this.cascadeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
         this.tileHorizontalToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
         this.tileVerticalToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
         this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
         this.menuStrip1.SuspendLayout();
         this.SuspendLayout();
         // 
         // menuStrip1
         // 
         this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.fileToolStripMenuItem,
            this.windowToolStripMenuItem});
         this.menuStrip1.Location = new System.Drawing.Point(0, 0);
         this.menuStrip1.MdiWindowListItem = this.windowToolStripMenuItem;
         this.menuStrip1.Name = "menuStrip1";
         this.menuStrip1.Size = new System.Drawing.Size(353, 24);
         this.menuStrip1.TabIndex = 1;
         this.menuStrip1.Text = "menuStrip1";
         // 
         // fileToolStripMenuItem
         // 
         this.fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.newToolStripMenuItem,
            this.exitToolStripMenuItem});
         this.fileToolStripMenuItem.Name = "fileToolStripMenuItem";
         this.fileToolStripMenuItem.Text = "File";
         // 
         // newToolStripMenuItem
         // 
         this.newToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.child1ToolStripMenuItem});
         this.newToolStripMenuItem.Name = "newToolStripMenuItem";
         this.newToolStripMenuItem.Text = "New";
         // 
         // child1ToolStripMenuItem
         // 
         this.child1ToolStripMenuItem.Name = "child1ToolStripMenuItem";
         this.child1ToolStripMenuItem.Text = "Child1";
         this.child1ToolStripMenuItem.Click += new System.EventHandler(this.child1ToolStripMenuItem_Click);
         // 
         // exitToolStripMenuItem
         // 
         this.exitToolStripMenuItem.Name = "exitToolStripMenuItem";
         this.exitToolStripMenuItem.Text = "Exit";
         // 
         // windowToolStripMenuItem
         // 
         this.windowToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.cascadeToolStripMenuItem,
            this.tileHorizontalToolStripMenuItem,
            this.tileVerticalToolStripMenuItem,
            this.toolStripSeparator1});
         this.windowToolStripMenuItem.Name = "windowToolStripMenuItem";
         this.windowToolStripMenuItem.Text = "Window";
         // 
         // cascadeToolStripMenuItem
         // 
         this.cascadeToolStripMenuItem.Name = "cascadeToolStripMenuItem";
         this.cascadeToolStripMenuItem.Text = "Cascade";
         this.cascadeToolStripMenuItem.Click += new System.EventHandler(this.cascadeToolStripMenuItem_Click);
         // 
         // tileHorizontalToolStripMenuItem
         // 
         this.tileHorizontalToolStripMenuItem.Name = "tileHorizontalToolStripMenuItem";
         this.tileHorizontalToolStripMenuItem.Text = "Tile Horizontal";
         this.tileHorizontalToolStripMenuItem.Click += new System.EventHandler(this.tileHorizontalToolStripMenuItem_Click);
         // 
         // tileVerticalToolStripMenuItem
         // 
         this.tileVerticalToolStripMenuItem.Name = "tileVerticalToolStripMenuItem";
         this.tileVerticalToolStripMenuItem.Text = "Tile Vertical";
         this.tileVerticalToolStripMenuItem.Click += new System.EventHandler(this.tileVerticalToolStripMenuItem_Click);
         // 
         // toolStripSeparator1
         // 
         this.toolStripSeparator1.Name = "toolStripSeparator1";
         // 
         // UsingMDIForm
         // 
         this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
         this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
         this.ClientSize = new System.Drawing.Size(353, 310);
         this.Controls.Add(this.menuStrip1);
         this.IsMdiContainer = true;
         this.MainMenuStrip = this.menuStrip1;
         this.Name = "UsingMDIForm";
         this.Text = "UsingMDI";
         this.menuStrip1.ResumeLayout(false);
         this.ResumeLayout(false);
         this.PerformLayout();
      }
    [STAThread]
    static void Main()
    {
        Application.EnableVisualStyles();
        Application.Run(new Form1());
    }
}
public class ChildForm : Form
{
   private System.Windows.Forms.PictureBox picDisplay;
   
   public ChildForm( string title, string fileName )
   {
      InitializeComponent();
      Text = title; 
      picDisplay.Image = Image.FromFile(fileName);
   }
   
   private void InitializeComponent() {
         this.picDisplay = new System.Windows.Forms.PictureBox();
         ((System.ruponentModel.ISupportInitialize)(this.picDisplay)).BeginInit();
         this.SuspendLayout();
         // 
         // picDisplay
         // 
         this.picDisplay.Location = new System.Drawing.Point(1, 7);
         this.picDisplay.Name = "picDisplay";
         this.picDisplay.Size = new System.Drawing.Size(225, 247);
         this.picDisplay.TabIndex = 0;
         this.picDisplay.TabStop = false;
         // 
         // ChildForm
         // 
         this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
         this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
         this.ClientSize = new System.Drawing.Size(227, 256);
         this.Controls.Add(this.picDisplay);
         this.Name = "ChildForm";
         this.Text = "Child";
         ((System.ruponentModel.ISupportInitialize)(this.picDisplay)).EndInit();
         this.ResumeLayout(false);
      }
}


MdiLayout.TileVertical

using System;
using System.Collections.Generic;
using System.ruponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
public class Form1 : Form
{
      private System.Windows.Forms.MenuStrip menuStrip1;
      private System.Windows.Forms.ToolStripMenuItem fileToolStripMenuItem;
      private System.Windows.Forms.ToolStripMenuItem newToolStripMenuItem;
      private System.Windows.Forms.ToolStripMenuItem exitToolStripMenuItem;
      private System.Windows.Forms.ToolStripMenuItem child1ToolStripMenuItem;
      private System.Windows.Forms.ToolStripMenuItem windowToolStripMenuItem;
      private System.Windows.Forms.ToolStripMenuItem cascadeToolStripMenuItem;
      private System.Windows.Forms.ToolStripMenuItem tileHorizontalToolStripMenuItem;
      private System.Windows.Forms.ToolStripMenuItem tileVerticalToolStripMenuItem;
      private System.Windows.Forms.ToolStripSeparator toolStripSeparator1;
      
      public Form1() {
        InitializeComponent();
      }
      private void child1ToolStripMenuItem_Click(object sender, EventArgs e ){
        ChildForm formChild = new ChildForm("Child", "winter.jpg" );
        formChild.MdiParent = this;
        formChild.Show();
     }
     private void cascadeToolStripMenuItem_Click(object sender, EventArgs e ) {
       this.LayoutMdi( MdiLayout.Cascade );
     } 
     private void tileHorizontalToolStripMenuItem_Click(object sender, EventArgs e ) {
       this.LayoutMdi( MdiLayout.TileHorizontal );
     }
     private void tileVerticalToolStripMenuItem_Click(object sender, EventArgs e ) {
       this.LayoutMdi( MdiLayout.TileVertical );
     }
     private void InitializeComponent() {
         this.menuStrip1 = new System.Windows.Forms.MenuStrip();
         this.fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
         this.newToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
         this.child1ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
         this.exitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
         this.windowToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
         this.cascadeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
         this.tileHorizontalToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
         this.tileVerticalToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
         this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
         this.menuStrip1.SuspendLayout();
         this.SuspendLayout();
         // 
         // menuStrip1
         // 
         this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.fileToolStripMenuItem,
            this.windowToolStripMenuItem});
         this.menuStrip1.Location = new System.Drawing.Point(0, 0);
         this.menuStrip1.MdiWindowListItem = this.windowToolStripMenuItem;
         this.menuStrip1.Name = "menuStrip1";
         this.menuStrip1.Size = new System.Drawing.Size(353, 24);
         this.menuStrip1.TabIndex = 1;
         this.menuStrip1.Text = "menuStrip1";
         // 
         // fileToolStripMenuItem
         // 
         this.fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.newToolStripMenuItem,
            this.exitToolStripMenuItem});
         this.fileToolStripMenuItem.Name = "fileToolStripMenuItem";
         this.fileToolStripMenuItem.Text = "File";
         // 
         // newToolStripMenuItem
         // 
         this.newToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.child1ToolStripMenuItem});
         this.newToolStripMenuItem.Name = "newToolStripMenuItem";
         this.newToolStripMenuItem.Text = "New";
         // 
         // child1ToolStripMenuItem
         // 
         this.child1ToolStripMenuItem.Name = "child1ToolStripMenuItem";
         this.child1ToolStripMenuItem.Text = "Child1";
         this.child1ToolStripMenuItem.Click += new System.EventHandler(this.child1ToolStripMenuItem_Click);
         // 
         // exitToolStripMenuItem
         // 
         this.exitToolStripMenuItem.Name = "exitToolStripMenuItem";
         this.exitToolStripMenuItem.Text = "Exit";
         // 
         // windowToolStripMenuItem
         // 
         this.windowToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.cascadeToolStripMenuItem,
            this.tileHorizontalToolStripMenuItem,
            this.tileVerticalToolStripMenuItem,
            this.toolStripSeparator1});
         this.windowToolStripMenuItem.Name = "windowToolStripMenuItem";
         this.windowToolStripMenuItem.Text = "Window";
         // 
         // cascadeToolStripMenuItem
         // 
         this.cascadeToolStripMenuItem.Name = "cascadeToolStripMenuItem";
         this.cascadeToolStripMenuItem.Text = "Cascade";
         this.cascadeToolStripMenuItem.Click += new System.EventHandler(this.cascadeToolStripMenuItem_Click);
         // 
         // tileHorizontalToolStripMenuItem
         // 
         this.tileHorizontalToolStripMenuItem.Name = "tileHorizontalToolStripMenuItem";
         this.tileHorizontalToolStripMenuItem.Text = "Tile Horizontal";
         this.tileHorizontalToolStripMenuItem.Click += new System.EventHandler(this.tileHorizontalToolStripMenuItem_Click);
         // 
         // tileVerticalToolStripMenuItem
         // 
         this.tileVerticalToolStripMenuItem.Name = "tileVerticalToolStripMenuItem";
         this.tileVerticalToolStripMenuItem.Text = "Tile Vertical";
         this.tileVerticalToolStripMenuItem.Click += new System.EventHandler(this.tileVerticalToolStripMenuItem_Click);
         // 
         // toolStripSeparator1
         // 
         this.toolStripSeparator1.Name = "toolStripSeparator1";
         // 
         // UsingMDIForm
         // 
         this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
         this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
         this.ClientSize = new System.Drawing.Size(353, 310);
         this.Controls.Add(this.menuStrip1);
         this.IsMdiContainer = true;
         this.MainMenuStrip = this.menuStrip1;
         this.Name = "UsingMDIForm";
         this.Text = "UsingMDI";
         this.menuStrip1.ResumeLayout(false);
         this.ResumeLayout(false);
         this.PerformLayout();
      }
    [STAThread]
    static void Main()
    {
        Application.EnableVisualStyles();
        Application.Run(new Form1());
    }
}
public class ChildForm : Form
{
   private System.Windows.Forms.PictureBox picDisplay;
   
   public ChildForm( string title, string fileName )
   {
      InitializeComponent();
      Text = title; 
      picDisplay.Image = Image.FromFile(fileName);
   }
   
   private void InitializeComponent() {
         this.picDisplay = new System.Windows.Forms.PictureBox();
         ((System.ruponentModel.ISupportInitialize)(this.picDisplay)).BeginInit();
         this.SuspendLayout();
         // 
         // picDisplay
         // 
         this.picDisplay.Location = new System.Drawing.Point(1, 7);
         this.picDisplay.Name = "picDisplay";
         this.picDisplay.Size = new System.Drawing.Size(225, 247);
         this.picDisplay.TabIndex = 0;
         this.picDisplay.TabStop = false;
         // 
         // ChildForm
         // 
         this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
         this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
         this.ClientSize = new System.Drawing.Size(227, 256);
         this.Controls.Add(this.picDisplay);
         this.Name = "ChildForm";
         this.Text = "Child";
         ((System.ruponentModel.ISupportInitialize)(this.picDisplay)).EndInit();
         this.ResumeLayout(false);
      }
}


MDI Relatives

/*
User Interfaces in C#: Windows Forms and Custom Controls
by Matthew MacDonald
Publisher: Apress
ISBN: 1590590457
*/
using System;
using System.Drawing;
using System.Collections;
using System.ruponentModel;
using System.Windows.Forms;
namespace MDIRelatives
{
  /// <summary>
  /// Summary description for MDIRelatives.
  /// </summary>
  public class MDIRelatives : System.Windows.Forms.Form
  {
    internal System.Windows.Forms.MainMenu MainMenu1;
    internal System.Windows.Forms.MenuItem MenuItem1;
    internal System.Windows.Forms.MenuItem mnuCascade;
    internal System.Windows.Forms.MenuItem mnuTileV;
    internal System.Windows.Forms.MenuItem mnuTileH;
    internal System.Windows.Forms.MenuItem mnuMinimizeAll;
    internal System.Windows.Forms.ImageList imgButtons;
    internal System.Windows.Forms.ToolBar ToolBar1;
    internal System.Windows.Forms.ToolBarButton cmdNew;
    internal System.Windows.Forms.ToolBarButton cmdClose;
    private System.ruponentModel.IContainer components;
    public MDIRelatives()
    {
      //
      // Required for Windows Form Designer support
      //
      InitializeComponent();
      //
      // TODO: Add any constructor code after InitializeComponent call
      //
    }
    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    protected override void Dispose( bool disposing )
    {
      if( disposing )
      {
        if(components != null)
        {
          components.Dispose();
        }
      }
      base.Dispose( disposing );
    }
    #region Windows Form Designer generated code
    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
      this.ruponents = new System.ruponentModel.Container();
      System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(MDIRelatives));
      this.MainMenu1 = new System.Windows.Forms.MainMenu();
      this.MenuItem1 = new System.Windows.Forms.MenuItem();
      this.mnuCascade = new System.Windows.Forms.MenuItem();
      this.mnuTileV = new System.Windows.Forms.MenuItem();
      this.mnuTileH = new System.Windows.Forms.MenuItem();
      this.mnuMinimizeAll = new System.Windows.Forms.MenuItem();
      this.imgButtons = new System.Windows.Forms.ImageList(this.ruponents);
      this.ToolBar1 = new System.Windows.Forms.ToolBar();
      this.cmdNew = new System.Windows.Forms.ToolBarButton();
      this.cmdClose = new System.Windows.Forms.ToolBarButton();
      this.SuspendLayout();
      // 
      // MainMenu1
      // 
      this.MainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
                                            this.MenuItem1});
      // 
      // MenuItem1
      // 
      this.MenuItem1.Index = 0;
      this.MenuItem1.MdiList = true;
      this.MenuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
                                            this.mnuCascade,
                                            this.mnuTileV,
                                            this.mnuTileH,
                                            this.mnuMinimizeAll});
      this.MenuItem1.Text = "Window";
      // 
      // mnuCascade
      // 
      this.mnuCascade.Index = 0;
      this.mnuCascade.Text = "Cascase";
      this.mnuCascade.Click += new System.EventHandler(this.mnuCascade_Click);
      // 
      // mnuTileV
      // 
      this.mnuTileV.Index = 1;
      this.mnuTileV.Text = "Tile Vertical";
      this.mnuTileV.Click += new System.EventHandler(this.mnuTileV_Click);
      // 
      // mnuTileH
      // 
      this.mnuTileH.Index = 2;
      this.mnuTileH.Text = "Tile Horizontal";
      this.mnuTileH.Click += new System.EventHandler(this.mnuTileH_Click);
      // 
      // mnuMinimizeAll
      // 
      this.mnuMinimizeAll.Index = 3;
      this.mnuMinimizeAll.Text = "Minimize All";
      this.mnuMinimizeAll.Click += new System.EventHandler(this.mnuMinimizeAll_Click);
      // 
      // imgButtons
      // 
      this.imgButtons.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit;
      this.imgButtons.ImageSize = new System.Drawing.Size(16, 16);
      this.imgButtons.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imgButtons.ImageStream")));
      this.imgButtons.TransparentColor = System.Drawing.Color.Transparent;
      // 
      // ToolBar1
      // 
      this.ToolBar1.Appearance = System.Windows.Forms.ToolBarAppearance.Flat;
      this.ToolBar1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
      this.ToolBar1.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {
                                            this.cmdNew,
                                            this.cmdClose});
      this.ToolBar1.DropDownArrows = true;
      this.ToolBar1.ImageList = this.imgButtons;
      this.ToolBar1.Name = "ToolBar1";
      this.ToolBar1.ShowToolTips = true;
      this.ToolBar1.Size = new System.Drawing.Size(292, 41);
      this.ToolBar1.TabIndex = 4;
      this.ToolBar1.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.ToolBar1_ButtonClick);
      // 
      // cmdNew
      // 
      this.cmdNew.ImageIndex = 0;
      this.cmdNew.Text = "New";
      // 
      // cmdClose
      // 
      this.cmdClose.ImageIndex = 1;
      this.cmdClose.Text = "Close";
      // 
      // MDIRelatives
      // 
      this.AutoScaleBaseSize = new System.Drawing.Size(5, 14);
      this.ClientSize = new System.Drawing.Size(292, 266);
      this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                      this.ToolBar1});
      this.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
      this.IsMdiContainer = true;
      this.Menu = this.MainMenu1;
      this.Name = "MDIRelatives";
      this.Text = "MDIRelatives";
      this.ResumeLayout(false);
    }
    #endregion
    [STAThread]
    static void Main() 
    {
      Application.Run(new MDIRelatives());
    }
    private string synchronizedText = "text";
    private int mdiCount = 0;
    private void ToolBar1_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
    {
      // Determine which button was clicked.
      if (e.Button == cmdNew)
      {
        // Show a new ChildForm.
        Child frmChild = new Child();
        frmChild.MdiMDIRelatives = this;
        frmChild.RefreshText(synchronizedText);
        mdiCount++;
        frmChild.Text = "MDI Child # " + mdiCount.ToString();
        frmChild.Show();
      }
      else if (e.Button == cmdClose)
      {
        // Close the active child.
        this.ActiveMdiChild.Close();
      }
    }
    public void RefreshChildren(Child sender, string text)
    {
      // Store text for use when creating a child form, or if needed later.
      synchronizedText = text;
      // Update children.
      foreach (Child frm in this.MdiChildren)
      {
        if (frm != sender)
        {
          frm.RefreshText(text);
        }
      }
    }
    private void mnuMinimizeAll_Click(object sender, System.EventArgs e)
    {
      foreach (Form frm in this.MdiChildren)
      {
        frm.WindowState = FormWindowState.Minimized;
      }
    }
    private void mnuTileH_Click(object sender, System.EventArgs e)
    {
      this.LayoutMdi(MdiLayout.TileHorizontal);
    }
    private void mnuTileV_Click(object sender, System.EventArgs e)
    {
      this.LayoutMdi(MdiLayout.TileVertical);
    }
    private void mnuCascade_Click(object sender, System.EventArgs e)
    {
      this.LayoutMdi(MdiLayout.Cascade);
    }

  }
}
//===========================================================
//===========================================================
using System;
using System.Drawing;
using System.Collections;
using System.ruponentModel;
using System.Windows.Forms;
namespace MDIRelatives
{
  /// <summary>
  /// Summary description for Child.
  /// </summary>
  public class Child : System.Windows.Forms.Form
  {
    /// <summary>
    /// Required designer variable.
    /// </summary>
    private System.ruponentModel.Container components = null;
    public Child()
    {
      //
      // Required for Windows Form Designer support
      //
      InitializeComponent();
      //
      // TODO: Add any constructor code after InitializeComponent call
      //
    }
    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    protected override void Dispose( bool disposing )
    {
      if( disposing )
      {
        if(components != null)
        {
          components.Dispose();
        }
      }
      base.Dispose( disposing );
    }
    #region Windows Form Designer generated code
    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
      this.textBox1 = new System.Windows.Forms.TextBox();
      this.SuspendLayout();
      // 
      // textBox1
      // 
      this.textBox1.Anchor = (((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
        | System.Windows.Forms.AnchorStyles.Left) 
        | System.Windows.Forms.AnchorStyles.Right);
      this.textBox1.Location = new System.Drawing.Point(8, 8);
      this.textBox1.Multiline = true;
      this.textBox1.Name = "textBox1";
      this.textBox1.Size = new System.Drawing.Size(212, 108);
      this.textBox1.TabIndex = 1;
      this.textBox1.Text = "textBox1";
      this.textBox1.TextChanged += new System.EventHandler(this.TextBox1_TextChanged);
      // 
      // Child
      // 
      this.AutoScaleBaseSize = new System.Drawing.Size(5, 14);
      this.ClientSize = new System.Drawing.Size(228, 126);
      this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                      this.textBox1});
      this.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
      this.Name = "Child";
      this.Text = "Child";
      this.ResumeLayout(false);
    }
    #endregion
    internal System.Windows.Forms.TextBox textBox1;

    private bool isUpdating;
    private void TextBox1_TextChanged(object sender, System.EventArgs e)
    {
      if (this.MdiParent != null && !isUpdating)
      {
        // The reference to the MDI parent must be converted to the appropriate
        // form class in order to access the custom RefreshChildren() method.
        ((Parent)this.MdiParent).RefreshChildren(this, textBox1.Text);
      }
    }
    public void RefreshText(string text)
    {
      // Disable the event to prevent an endless string of updates.
      isUpdating = true;
      // Update the control.
      textBox1.Text = text;
      // Re-enable the event handler.
      isUpdating = false;
    }
  }
}

<A href="http://www.nfex.ru/Code/CSharpDownload/MDIRelatives.zip">MDIRelatives.zip( 38 k)</a>


Set MDI parent window

using System;
using System.Collections.Generic;
using System.ruponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
  public class Form2 : Form
  {
    private System.Windows.Forms.Button Button3;
    private System.Windows.Forms.Button Button2;
    private System.Windows.Forms.Button Button1;
      
      
    public Form2()
    {
      InitializeComponent();
    }
    private void InitializeComponent()
    {
      this.Button3 = new System.Windows.Forms.Button();
      this.Button2 = new System.Windows.Forms.Button();
      this.Button1 = new System.Windows.Forms.Button();
      this.SuspendLayout();
      // 
      // Button3
      // 
      this.Button3.Location = new System.Drawing.Point(120, 56);
      this.Button3.Name = "Button3";
      this.Button3.Size = new System.Drawing.Size(88, 32);
      this.Button3.TabIndex = 8;
      this.Button3.Text = "Become Child of Parent2";
      this.Button3.Click += new System.EventHandler(this.Button3_Click);
      // 
      // Button2
      // 
      this.Button2.Location = new System.Drawing.Point(12, 56);
      this.Button2.Name = "Button2";
      this.Button2.Size = new System.Drawing.Size(88, 32);
      this.Button2.TabIndex = 7;
      this.Button2.Text = "Become Child of Parent1";
      this.Button2.Click += new System.EventHandler(this.Button2_Click);
      // 
      // Button1
      // 
      this.Button1.Location = new System.Drawing.Point(12, 12);
      this.Button1.Name = "Button1";
      this.Button1.Size = new System.Drawing.Size(88, 32);
      this.Button1.TabIndex = 6;
      this.Button1.Text = "Become Parent";
      this.Button1.Click += new System.EventHandler(this.Button1_Click);
      // 
      // Form2
      // 
      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
      this.ClientSize = new System.Drawing.Size(292, 154);
      this.Controls.Add(this.Button3);
      this.Controls.Add(this.Button2);
      this.Controls.Add(this.Button1);
      this.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
      this.Name = "Form2";
      this.Text = "Form2";
      this.ResumeLayout(false);
    }
    private void Button1_Click(object sender, System.EventArgs e)
    {
      this.Hide();
      this.MdiParent = null;
      this.IsMdiContainer = true;
      this.Show();
    }
    private void Button2_Click(object sender, System.EventArgs e)
    {
      this.Hide();
      this.IsMdiContainer = false;
      this.MdiParent = Program.Main2;
      this.Show();
    }
    private void Button3_Click(object sender, System.EventArgs e)
    {
      this.Hide();
      this.IsMdiContainer = false;
      this.MdiParent = Program.Main1;
      this.Show();
    }
  }
  public class Form1 : Form
  {
    public Form1()
    {
      InitializeComponent();
    }
    private void Form1_FormClosed(object sender, FormClosedEventArgs e)
    {
      Application.Exit();
    }
    private void InitializeComponent()
    {
      this.SuspendLayout();
      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
      this.ClientSize = new System.Drawing.Size(422, 351);
      this.IsMdiContainer = true;
      this.Name = "Form1";
      this.Text = "Form1";
      this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.Form1_FormClosed);
      this.ResumeLayout(false);
    }
  }
  static class Program
  {
    public static Form1 Main1 = new Form1();
    public static Form1 Main2 = new Form1();
    public static Form2 Child = new Form2();
    [STAThread]
    public static void Main()
    {
      Application.EnableVisualStyles();
      Main1.Text = "Parent 2";
      Main2.Text = "Parent 1";
      Main1.Show();
      Main2.Show();
      Child.MdiParent = Main2;
      Child.Show();
      System.Windows.Forms.Application.Run();
    }
  }