码迷,mamicode.com
首页 > Windows程序 > 详细

MDI窗体

时间:2016-07-03 21:41:36      阅读:287      评论:0      收藏:0      [点我收藏+]

标签:

将窗体属性里面IsMdiContainer的值改为true

技术分享

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

        private void label1_Click(object sender, EventArgs e)
        {

        }
        
        private void 销售模块ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            bool has = false;
            Form2 f2=new Form2();
            f2.WindowState = FormWindowState.Maximized;//开启窗口最大化
            foreach (Form f in this.MdiChildren)
            {
                if (f.Name == f2.Name)//判断集合中是否有该窗体
                {
                    has = true;//记录一下含有该窗体
                    f.Show();//已经打开的窗体继续显示
                    f2.Close();//关闭新建窗体
                }
            }
            if (has)//如果有该窗体
            {
                foreach (Form f in this.MdiChildren)
                {
                    if (f.Name != f2.Name)
                    {
                        f.Hide();//其余窗体都隐藏
                    }
                }
            }
            else//如果没有该窗体
            {
                f2.MdiParent = this;//将f2窗体放入mdi窗体中
                f2.Show();//显示该窗体
            }

        }

        private void 仓库模块ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            bool has = false;
            Form3 f3 = new Form3();
            f3.WindowState = FormWindowState.Maximized;
            foreach (Form f in this.MdiChildren)
            {
                if (f.Name == f3.Name)
                {
                    has = true;
                    f.Show();
                    f3.Close();
                }
            }
            if (has)
            {
                foreach (Form f in this.MdiChildren)
                {
                    if (f.Name != f3.Name)
                    {
                        f.Hide();
                    }
                }
            }
            else
            {
                f3.MdiParent = this;
                f3.Show();
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
    }
}

技术分享

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


        private void Form2_Load(object sender, EventArgs e)
        {

        }
    }
}

技术分享

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

        private void Form3_Load(object sender, EventArgs e)
        {

        }
    }
}

技术分享

技术分享

技术分享

 

MDI窗体

标签:

原文地址:http://www.cnblogs.com/fengsantianya/p/5638668.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!