winform窗体 控件【MDI 窗体容器】

 

  MDI :窗体容器

                                               -- 在窗体中放置窗体

属性

IsMdiContainer  : 是否是窗体          -- 只有 Form 有此属性

 

   Form2 f2 = new Form2();

  f2.MdiParent = this;                                                          -- 获取或设置此窗体的父窗体 

  f2.WindowState = FormWindowState.Maximized;          --在后台设置窗体最大化  

  f2.Parent = panel1;                        -- 获取或设置此控件的父容器(放置了 panel 来布局要将窗体放到 panel 上面) 

  f2.Show();

 

案例

        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 == false)
            {
                f2.MdiParent = this;
                f2.WindowState = FormWindowState.Maximized;
                f2.Parent = panel1;
                f2.Show();
                FormList.Add(f2);
            }
            else
            {
                foreach (Form f in FormList)
                {
                    f.Hide();
                }
                f2.Show();
            }
        }

        private void 仓库模块ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            bool has = false;
            Form3 f3 = new Form3();

            foreach (Form f in FormList)
            {
                if (f is Form3)
                {
                    has = true;
                    f3 = f as Form3;
                }
            }

            if (has == false)
            {
                f3.MdiParent = this;
                f3.WindowState = FormWindowState.Maximized;
                f3.Parent = panel1;
                f3.Show();
                FormList.Add(f3);
            }
            else
            {
                foreach (Form f in FormList)
                {
                    f.Hide();
                }
                f3.Show();
            }
        }

        private void 财务模块ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form4 f4 = new Form4();
            f4.MdiParent = this;
            f4.WindowState = FormWindowState.Maximized;
            f4.Parent = panel1;
            f4.Show();
        }
View Code

销售模块 与 仓库模块 使用 MID 容器并且打开单一窗体

财务模:使用 MID 容器

 

posted @ 2017-05-06 16:46  唐宏昌  阅读(669)  评论(0编辑  收藏  举报