码迷,mamicode.com
首页 > 其他好文 > 详细

MDI 窗口的创建

时间:2017-10-07 14:24:23      阅读:193      评论:0      收藏:0      [点我收藏+]

标签:Owner   icon   too   space   add   http   log   collect   com   

1、创建MDI 的父窗口 FormMain

设置窗口的IsMDIContainer 的属性为True

技术分享

技术分享

 

 

2、创建MDI 的子窗口

在“添加新项”对话框中,选择“Windows 窗体”(在 Visual Basic 中或 Visual C# 中)或从“模板”窗格中选择“Windows 窗体应用程序 (.NET)”(在 Visual C++ 中)。 在“名称”框中,将窗体命名为 Form2。 单击“打开”按钮,将窗体添加到项目中。

技术分享

 

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MDI
{
    public partial class FormMain : Form
    {
        public FormMain()
        {
            InitializeComponent();
            
        }

        private void 新建NToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form fr1 = new Form();
            fr1.MdiParent = this;
            fr1.Show();
        }

        private void 打开OToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FormMDI1 frmMDI1 = new FormMDI1();
            frmMDI1.MdiParent = this;
            frmMDI1.Show();

            FormMDI2 frmMDI2 = new FormMDI2();
            frmMDI2.MdiParent = this;
            //frmMDI2.Owner = this;
            frmMDI2.Show();

            FormMDI3 frmMDI3 = new FormMDI3();
            frmMDI3.MdiParent = this;
            frmMDI3.Show();
        }

        private void FiletoolStripMenuItem1_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.Cascade);
        }

        private void NewStripMenuItem2_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.TileHorizontal);
        }

        private void 垂直排列ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.TileVertical);
        }

        private void 退出XToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
            this.Dispose();
        }
    }
}

 

备注:此程序创建了三个MDI 的子窗口,通过菜单栏的打开同时显示三个子窗口,使用窗口布局菜单切换MDI 子窗口的布局

技术分享

 

MDI 窗口的创建

标签:Owner   icon   too   space   add   http   log   collect   com   

原文地址:http://www.cnblogs.com/wenjie0904/p/7634375.html

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