C#學習筆記——MDI窗體(多文檔界面)

 

一、設置父窗體:

若是要將某個窗體設置爲父窗體,只需將該窗體的IsMdiContainer屬性設置爲True便可。app

 

二、設置子窗體:

經過設爲某個窗體的MdiParent屬性來肯定該窗體是那個窗體的子窗體。佈局

語法以下:post

   public Form MdiParent{get;set;}
三、排列MDI子窗體:

語法以下:this

   public void LayoutMdi(MdiLayout value)

value:是MdiLayout的枚舉值之一,用來定義MDI子窗體的佈局。spa

枚舉成員 說明
Cascade 層疊排列MDI子窗體
TileHorizontal 水平平鋪MDI子窗體
TileVertical 垂直平鋪MDI子窗體

例程;code

image

    public partial class FormMain : Form
   {
            public FormMain()
            {
                InitializeComponent();
            }
     
            private void 加載子窗體ToolStripMenuItem_Click(object sender, EventArgs e)
            {
               FormChild_1 frm1 = new FormChild_1();
               frm1.MdiParent = this;
               frm1.Show();
    
               FormChild_2 frm2 = new FormChild_2();
               frm2.MdiParent = this;
               frm2.Show();
    
               FormChild_3 frm3 = new FormChild_3();
               frm3.MdiParent = this;
               frm3.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);
           }
   
      }
相關文章
相關標籤/搜索