All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
asp.net将Execl读到DataSet或DataTable中_[Asp.Net教程]
SQL Server2005数字转中文大写字母_[SQL Server教程]
asp.net访问IIS元数据库失败问题解决_[Asp.Net教程]
SQL数据库高级教程:SQL ALTER TABLE_[SQL Server教程]
PHP漏洞中的战争_[PHP教程]
Login控件在UpdatePanel内当验证用户信息成功后出现页面刷新的解决办法_[Asp.Net教程]
教你IIS6的PHP最佳配置方法_[PHP教程]
delphi工程选项及桌面配置文件(.dof)
DataGrid行单击和双击事件实现代码_[Asp.Net教程]
DELPHI构件的概念以及制作方法
Reading number is top 10 pictures
何炅哥为中国人的平均工资鸣不平了
西班牙山村小景3
9.3阅兵全景图3-外国方阵梯队和坦克方阵梯队
So beauty, will let you spray blood5
某某人向找小三的人宣战了
超强高考作文
XuRe xuan cool and refreshing photoes1
NeedWallpaper4
30 beautiful school beauty2
The little girl with long hair3
Download software ranking
The king of fighters 97(Mobile phone games-apk)
jdk1.6 for windows
Unix video tutorial18
美女写真1
Boxer Classic video3
WebService在.NET中的实战应用教学视频 → 第5集
Unix video tutorial20
The cock of the Grosvenor LTD handsome
Tram sex maniac 2 (H) rar bag10
C++编程教程第三版
qq published in(发表于) 2014/7/11 9:18:57 Edit(编辑)
C#中创建MDI应用程序

C#中创建MDI应用程序

C#中创建MDI应用程序

创建MDI应用程序

本节通过一个实例介绍创建MDI应用程序的具体过程及设置窗体的布局。实例运行结果如图1所示。



图1 MDI应用程序运行结果

程序开发步骤如下。

(1)新建一个Windows应用程序,命名为07_02,默认窗体为Form1.cs。

(2)将窗体Form1的IsMdiContainer属性设置为True,作为MDI父窗体,然后再添加两个Windows窗体,作为MDI子窗体。

(3)在Form1窗体中,添加一个MenuStrip控件,作为该父窗体的菜单项。

(4)程序主要代码如下。

MDI父窗体Form1中,声明MDI子窗体Form2和Form3的两个实例对象,并给它们赋值为null,用来判断子窗体是第一次打开,还是已经加载过而被释放掉了。声明MDI子窗体Form2和Form3对象的代码如下:

Form2 frmChild1 = null;

Form3 frmChild2 = null;

单击“打开子窗体1”菜单项时,程序首先判断“子窗体1”是否打开,如果没有,则实例化一个新的对象,并以当前窗体为父窗体进行显示,否则,判断“子窗体1”的对象是否释放。如果释放,则重新实例化一个对象;如果没有释放,则获得“子窗体1”对象的焦点。“打开子窗体1”菜单项的Click事件代码如下:

private void 打开子窗体1ToolStripMenuItem_Click(object sender, EventArgs e)

{

if (frmChild1 == null)

{

frmChild1 = new Form2();

frmChild1.MdiParent = this;

frmChild1.Show();

}

else

{

if (frmChild1.IsDisposed)

{

frmChild1 = new Form2();

}

frmChild1.MdiParent = this;

frmChild1.Show();

frmChild1.Focus();

}

}

说明:“打开子窗体2”菜单项的Click事件与“打开子窗体1”菜单项的Click事件代码实现原理类似,其详细代码请参见本书附带光盘。

单击“水平排列”菜单项时,如果父窗体中有多个子窗体,程序会将这些窗体按照一定的顺序水平排列在父窗体中。“水平排列”菜单项的Click事件代码如下:

private void 水平排列ToolStripMenuItem_Click(object sender, EventArgs e)

{

LayoutMdi(MdiLayout.TileHorizontal);

}

说明:“垂直排列”菜单项的Click事件与“水平排列”菜单项的Click事件代码实现原理类似,其详细代码请参见本书附带光盘。

完整程序代码如下:

★ ★★★★Form1.cs窗体代码文件完整程序代码★★★★★

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

namespace _7_02

{

public partial class Form1 : Form

{

Form2 frmChild1 = null;

Form3 frmChild2 = null;

public Form1()

{

InitializeComponent();

}

private void 打开子窗体1ToolStripMenuItem_Click(object sender, EventArgs e)

{

if (frmChild1 == null)

{

frmChild1 = new Form2();

frmChild1.MdiParent = this;

frmChild1.Show();

}

else

{

if (frmChild1.IsDisposed)

{

frmChild1 = new Form2();

}

frmChild1.MdiParent = this;

frmChild1.Show();

frmChild1.Focus();

}

}

private void 打开子窗体2ToolStripMenuItem_Click(object sender, EventArgs e)

{

if (frmChild2 == null)

{

frmChild2 = new Form3();

frmChild2.MdiParent = this;

frmChild2.Show();

}

else

{

if (frmChild2.IsDisposed)

{

frmChild2 = new Form3();

}

frmChild2.MdiParent = this;

frmChild2.Show();

frmChild2.Focus();

}

}

private void 水平排列ToolStripMenuItem_Click(object sender, EventArgs e)

{

LayoutMdi(MdiLayout.TileHorizontal);

}

private void 垂直排列ToolStripMenuItem_Click(object sender, EventArgs e)

{

LayoutMdi(MdiLayout.TileVertical);

}

private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)

{

Application.Exit();

}

}

}

★ ★★★★Form1.designer.cs窗体设计文件完整程序代码★★★★★



添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.