1. 程式人生 > >winform 之MDI容器

winform 之MDI容器

for dip each code div ipa rm2 args windows

MDI是指將多控件窗體在同一窗體中打開

1、設置:屬性中IsMDIContainer:true;

窗體變為灰色成為MDI窗體容器

2、MDI中一般采用菜單作為打開方式

3、子級窗體在MDI中打開,需先設置位於MDI窗體中

例:

Form2 f2 = new Form2();
f2.MdiParent = this;
f2.Show();

4、窗口打開最大化

對象.WindowState=FormwindowState.Maximized

5、父級Panel容器中打開,為隱藏窗口還原按鈕

對象.Parent=Panel;

6、無邊框

FormBorderStyle:None;

7、窗口打開唯一

List<Form> formlist = new List<Form>();
        private void 銷售額ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //窗口唯一
            bool has = false;
            Form2 f2 = new Form2();
            foreach(Form f in formlist)
            {
                
if (f is Form2) { has = true; f2 = f as Form2; } } if (has) { foreach (Form f in formlist) { f.Hide(); } f2.Show(); }
else { //定義到MDI容器 f2.MdiParent = this; //打開最大化 f2.WindowState = FormWindowState.Maximized; //Panel父級 f2.Parent = panel1; //展示打開 f2.Show(); formlist.Add(f2); } }

winform 之MDI容器