1、設置父窗體:
如果要將某個窗體設置為父窗體,只需將該窗體的IsMdiContainer屬性設置為True即可。
2、設置子窗體:
通過設為某個窗體的MdiParent屬性來確定該窗體是那個窗體的子窗體。
語法如下:
1: public Form MdiParent{get;set;}
3、排列MDI子窗體:
語法如下:
1: public void LayoutMdi(MdiLayout value)
value:是MdiLayout的枚舉值之一,用來定義MDI子窗體的布局。
枚舉成員 說明 Cascade 層疊排列MDI子窗體 TileHorizontal 水平平鋪MDI子窗體 TileVertical 垂直平鋪MDI子窗體例程;
1: public partial class FormMain : Form 2: { 3: public FormMain() 4: { 5: InitializeComponent(); 6: } 7: 8: private void 加載子窗體ToolStripMenuItem_Click(object sender, EventArgs e) 9: { 10: FormChild_1 frm1 = new FormChild_1(); 11: frm1.MdiParent = this; 12: frm1.Show(); 13: 14: FormChild_2 frm2 = new FormChild_2(); 15: frm2.MdiParent = this; 16: frm2.Show(); 17: 18: FormChild_3 frm3 = new FormChild_3(); 19: frm3.MdiParent = this; 20: frm3.Show(); 21: } 22: 23: private void 水平平鋪ToolStripMenuItem_Click(object sender, EventArgs e) 24: { 25: LayoutMdi(MdiLayout.TileHorizontal); 26: } 27: 28: private void 垂直平鋪ToolStripMenuItem_Click(object sender, EventArgs e) 29: { 30: LayoutMdi(MdiLayout.TileVertical); 31: } 32: 33: private void 層疊排列ToolStripMenuItem_Click(object sender, EventArgs e) 34: { 35: LayoutMdi(MdiLayout.Cascade); 36: } 37: 38: }