WINFORM学习手册——Mdi应用(窗体布局)

一、打开上一章的项目,配置窗体菜单如下图:

image

二、选择菜单,更属性MdiWindowListItem为windowToolStripMenuItem,这样可以实现打开多个子窗体后,会在Window菜单下显示

image

三、双击菜单项(Cascade、The Horizontally、The Vertically),写入单击事件:

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 MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
        }
        /// <summary>
        /// 创建子窗体
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void newToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ChildForm childForm = new ChildForm();
            childForm.MdiParent = this;
            childForm.Show();
        }
        /// <summary>
        /// 层叠布局
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void cascadeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.LayoutMdi(MdiLayout.Cascade);
        }
        /// <summary>
        /// 横向布局            
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void theHorizontallyToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.LayoutMdi(MdiLayout.TileHorizontal);
        }
        /// <summary>
        /// 竖向布局
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void theVerticallyToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.LayoutMdi(MdiLayout.TileVertical);
        }
    }
}

执行:

多个子窗体,会在Window菜单项下面显示:

 

 

层叠布局:

image

横向布局:

image

竖向布局:

image

posted @ 2014-01-07 19:06  争世不悔  阅读(1386)  评论(0编辑  收藏  举报