代码改变世界

创建MDI窗口并控制子窗口的排列方式

2012-04-07 21:17  精诚所至 金石为开  阅读(1563)  评论(0编辑  收藏  举报

本例创建一个MDI窗口并控制子窗口排列方式为层叠、水平或垂直平铺,程序运行窗口如下。

20120408211210 20120408211221 20120408211230

 

 

利用Menustrip菜单控件,添加各菜单项鼠标事件,程序代码如下。

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
namespace eg36_MDIFromApp
{
	public partial class MainForm : Form
	{
		private static int FormCount=0;
		public MainForm()
		{
			InitializeComponent();
		}
		void 新建ToolStripMenuItemClick(object sender, EventArgs e)
		{
			Form frmTemp=new Form();
			frmTemp .MdiParent=this;
			frmTemp.Text="Window#"+FormCount.ToString();
			FormCount++;
			frmTemp.Show();
		}
		void 退出ToolStripMenuItemClick(object sender, EventArgs e)
		{
			this.Close();
		}
		void 层叠ToolStripMenuItemClick(object sender, EventArgs e)
		{
			this.LayoutMdi(MdiLayout.Cascade);
		}
		void 水平排列ToolStripMenuItemClick(object sender, EventArgs e)
		{
			this.LayoutMdi(MdiLayout.TileHorizontal);
		}
		void PToolStripMenuItemClick(object sender, EventArgs e)
		{
			this.LayoutMdi(MdiLayout.TileVertical);
		}
	}
}