1. 程式人生 > >C#-Mdi多文件視窗及其子視窗的排列 ---ShinePans

C#-Mdi多文件視窗及其子視窗的排列 ---ShinePans

MdiLayout列舉成員及說明
Casecade s所有Mdi層疊在父視窗
TileHorizontal 水平平鋪
TitleVertical 垂直平鋪


Form1.cs (mdi)

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 Test1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void 載入子窗體ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form2 frm2 = new Form2();  //例項化 Form2
            frm2.MdiParent = this;      //設定MdiParent屬性,將當前窗體作為父窗
            frm2.Show();   //使用show方法開啟窗體             
            Form3 frm3 = new Form3();
            frm3.MdiParent = this;
            frm3.Show();
            Form4 frm4 = new Form4();
            frm4.MdiParent = this;
            frm4.Show();
        }

        private void 水平平鋪ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.TileHorizontal);
        }

        private void 垂直平鋪ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.TileVertical);
        }

        private void 層疊排列ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.Cascade);
        }
    }
}

Form1.Designer
namespace Test1
{
    partial class Form1
    {
        /// <summary>
        /// 必需的設計器變數。
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// 清理所有正在使用的資源。
        /// </summary>
        /// <param name="disposing">如果應釋放託管資源,為 true;否則為 false。</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows 窗體設計器生成的程式碼

        /// <summary>
        /// 設計器支援所需的方法 - 不要
        /// 使用程式碼編輯器修改此方法的內容。
        /// </summary>
        private void InitializeComponent()
        {
            this.components = new System.ComponentModel.Container();
            this.menuStrip1 = new System.Windows.Forms.MenuStrip();
            this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components);
            this.載入子窗體ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.水平平鋪ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.垂直平鋪ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.層疊排列ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.menuStrip1.SuspendLayout();
            this.SuspendLayout();
            // 
            // menuStrip1
            // 
            this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.載入子窗體ToolStripMenuItem,
            this.水平平鋪ToolStripMenuItem,
            this.垂直平鋪ToolStripMenuItem,
            this.層疊排列ToolStripMenuItem});
            this.menuStrip1.Location = new System.Drawing.Point(0, 0);
            this.menuStrip1.Name = "menuStrip1";
            this.menuStrip1.Size = new System.Drawing.Size(648, 25);
            this.menuStrip1.TabIndex = 1;
            this.menuStrip1.Text = "menuStrip1";
            // 
            // contextMenuStrip1
            // 
            this.contextMenuStrip1.Name = "contextMenuStrip1";
            this.contextMenuStrip1.Size = new System.Drawing.Size(61, 4);
            // 
            // 載入子窗體ToolStripMenuItem
            // 
            this.載入子窗體ToolStripMenuItem.Name = "載入子窗體ToolStripMenuItem";
            this.載入子窗體ToolStripMenuItem.Size = new System.Drawing.Size(80, 21);
            this.載入子窗體ToolStripMenuItem.Text = "載入子窗體";
            this.載入子窗體ToolStripMenuItem.Click += new System.EventHandler(this.載入子窗體ToolStripMenuItem_Click);
            // 
            // 水平平鋪ToolStripMenuItem
            // 
            this.水平平鋪ToolStripMenuItem.Name = "水平平鋪ToolStripMenuItem";
            this.水平平鋪ToolStripMenuItem.Size = new System.Drawing.Size(68, 21);
            this.水平平鋪ToolStripMenuItem.Text = "水平平鋪";
            this.水平平鋪ToolStripMenuItem.Click += new System.EventHandler(this.水平平鋪ToolStripMenuItem_Click);
            // 
            // 垂直平鋪ToolStripMenuItem
            // 
            this.垂直平鋪ToolStripMenuItem.Name = "垂直平鋪ToolStripMenuItem";
            this.垂直平鋪ToolStripMenuItem.Size = new System.Drawing.Size(68, 21);
            this.垂直平鋪ToolStripMenuItem.Text = "垂直平鋪";
            this.垂直平鋪ToolStripMenuItem.Click += new System.EventHandler(this.垂直平鋪ToolStripMenuItem_Click);
            // 
            // 層疊排列ToolStripMenuItem
            // 
            this.層疊排列ToolStripMenuItem.Name = "層疊排列ToolStripMenuItem";
            this.層疊排列ToolStripMenuItem.Size = new System.Drawing.Size(68, 21);
            this.層疊排列ToolStripMenuItem.Text = "層疊排列";
            this.層疊排列ToolStripMenuItem.Click += new System.EventHandler(this.層疊排列ToolStripMenuItem_Click);
            // 
            // Form1
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.BackColor = System.Drawing.SystemColors.Window;
            this.ClientSize = new System.Drawing.Size(648, 309);
            this.Controls.Add(this.menuStrip1);
            this.IsMdiContainer = true;
            this.MainMenuStrip = this.menuStrip1;
            this.Name = "Form1";
            this.Text = "Form1";
            this.Load += new System.EventHandler(this.Form1_Load);
            this.menuStrip1.ResumeLayout(false);
            this.menuStrip1.PerformLayout();
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion

        private System.Windows.Forms.MenuStrip menuStrip1;
        private System.Windows.Forms.ToolStripMenuItem 載入子窗體ToolStripMenuItem;
        private System.Windows.Forms.ToolStripMenuItem 水平平鋪ToolStripMenuItem;
        private System.Windows.Forms.ToolStripMenuItem 垂直平鋪ToolStripMenuItem;
        private System.Windows.Forms.ToolStripMenuItem 層疊排列ToolStripMenuItem;
        private System.Windows.Forms.ContextMenuStrip contextMenuStrip1;

    }
}
Form2.cs  Form3.Cs Form4.cs 為預設值