电信主站 网通分站
购买流程 付款方式 常见问题 在线提问 续租服务 购物车
用户名: 密 码: 忘记密码?
首 页
域名注册
虚拟主机
双线主机
服务器租用
VPS主机
企业邮局
代理专区
客服中心
虚拟主机行业资讯 虚拟主机评测对比 互联网最新动态 技术学院 站长资讯 在线教程 网站运营
搜索优化 服务器 网络编程 图形图象 站长之家 网页制作 操作系统
冲浪宝典 软件教学 视频通信 办公软件 邮件系统 网络安全 认证考试
您当前位置:西部数码->资讯中心-> 在线教程-> .NET
制作自己的控制台-.NET教程,C#语言
作者:网友供稿 点击:6
  西部数码-全国虚拟主机10强!20余项虚拟主机管理功能,全国领先!第6代双线路虚拟主机,南北访问畅通无阻!虚拟主机可在线rar解压,自动数据恢复设置虚拟目录等.虚拟主机免费赠送访问统计,企业邮局.Cn域名注册10元/年,自助建站480元起,免费试用7天,满意再付款!P4主机租用799元/月.月付免压金!
文章页数:[1] 
日前,有人问道:如何把一个子窗口设置为主窗口的“控制台”,也就是说,要在它上面进行一些系统性的操作。比如:功能的划分,子功能的调用。如果这样做出来的话,那么,它就具有操作直观性了。
好了,废话不说了,进入正题吧:)

我们用一种方法:加一个子窗口,并设置该子窗口为最底层,在该子窗口上加一个可拉伸的图片框。当该子窗口被激活,就把它设置为最底层。并且,不允许用户关闭它,就可以了。
具体方法:
加载一个子窗口(form1),并重写该子窗口的onactivated事件:
protected override void onactivated(eventargs e)
{
sendtoback();
}
===================
在该子窗口上加上你要的picturebox
在主窗口中加载一个空窗口:form mdichile = null;
写主窗口的mdichildactiveate事件:
private void mainform_mdichildactivate(object sender, system.eventargs e)
{
form form = this.activemdichild;
if(form != null)
{
if(form is form1)
{
if(mdichile != null)
{
mdichile.activate();
}
}
else
{
mdichile = form;
}
}
else
{
form1.activate();
}
}
==================
这就可以了。:-)


下面是它的源代码:
源代码form1(主窗口):
using system;
using system.drawing;
using system.collections;
using system.componentmodel;
using system.windows.forms;
using system.data;

namespace demo
{
/// <summary>
/// form1 的摘要说明。
/// </summary>
public class form1 : system.windows.forms.form
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private system.componentmodel.container components = null;
private system.windows.forms.mainmenu mainmenu1;
private system.windows.forms.menuitem menuitem1;
private system.windows.forms.menuitem menuitem2;
private form form = null;
private form3 form3 = new form3();

public form1()
{
//
// windows 窗体设计器支持所必需的
//
initializecomponent();

//
// todo: 在 initializecomponent 调用后添加任何构造函数代码
//
}

/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.dispose();
}
}
base.dispose( disposing );
}

#region windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void initializecomponent()
{
this.mainmenu1 = new system.windows.forms.mainmenu();
this.menuitem1 = new system.windows.forms.menuitem();
this.menuitem2 = new system.windows.forms.menuitem();
//
// mainmenu1
//
this.mainmenu1.menuitems.addrange(new system.windows.forms.menuitem[] {
this.menuitem1});
//
// menuitem1
//
this.menuitem1.index = 0;
this.menuitem1.menuitems.addrange(new system.windows.forms.menuitem[] {
this.menuitem2});
this.menuitem1.text = "123";
//
// menuitem2
//
this.menuitem2.index = 0;
this.menuitem2.text = "123";
this.menuitem2.click += new system.eventhandler(this.menuitem2_click);
//
// form1
//
this.autoscalebasesize = new system.drawing.size(6, 14);
this.clientsize = new system.drawing.size(508, 302);
this.ismdicontainer = true;
this.menu = this.mainmenu1;
this.name = "form1";
this.text = "form1";
this.mdichildactivate += new system.eventhandler(this.form1_mdichildactivate);
this.load += new system.eventhandler(this.form1_load);

}
#endregion

/// <summary>
/// 应用程序的主入口点。
/// </summary>
[stathread]
static void main()
{
application.run(new form1());
}

private void menuitem2_click(object sender, system.eventargs e)
{
form2 form = new form2();
form.mdiparent = this;
form.show();
}

private void form1_mdichildactivate(object sender, system.eventargs e)
{
form theform = this.activemdichild;
if(theform != null)
{
if(theform is form3)
{
if(form != null)
{
this.form.activate();
}
}
else
{
form = theform;
}
}
else
{
form3.activate();
}
}

private void form1_load(object sender, system.eventargs e)
{
form3.mdiparent = this;
form3.show();
}
}
}
==================
form2:
using system;
using system.drawing;
using system.collections;
using system.componentmodel;
using system.windows.forms;

namespace demo
{
/// <summary>
/// form2 的摘要说明。
/// </summary>
public class form2 : system.windows.forms.form
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private system.componentmodel.container components = null;

public form2()
{
//
// windows 窗体设计器支持所必需的
//
initializecomponent();

//
// todo: 在 initializecomponent 调用后添加任何构造函数代码
//
}

/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.dispose();
}
}
base.dispose( disposing );
}

#region windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void initializecomponent()
{
this.components = new system.componentmodel.container();
this.size = new system.drawing.size(300,300);
this.text = "form2";
}
#endregion
}
}
=============================
form3(底层窗口):
using system;
using system.drawing;
using system.collections;
using system.componentmodel;
using system.windows.forms;

namespace demo
{
/// <summary>
/// form3 的摘要说明。
/// </summary>
public class form3 : system.windows.forms.form
{
private system.windows.forms.button button1;
private system.windows.forms.button button2;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private system.componentmodel.container components = null;

public form3()
{
//
// windows 窗体设计器支持所必需的
//
initializecomponent();

//
// todo: 在 initializecomponent 调用后添加任何构造函数代码
//
}

/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.dispose();
}
}
base.dispose( disposing );
}

#region windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void initializecomponent()
{
this.button1 = new system.windows.forms.button();
this.button2 = new system.windows.forms.button();
this.suspendlayout();
//
// button1
//
this.button1.location = new system.drawing.point(12, 32);
this.button1.name = "button1";
this.button1.tabindex = 1;
this.button1.text = "button1";
this.button1.click += new system.eventhandler(this.button1_click);
//
// button2
//
this.button2.location = new system.drawing.point(16, 72);
this.button2.name = "button2";
this.button2.tabindex = 2;
this.button2.text = "button2";
this.button2.click += new system.eventhandler(this.button2_click);
//
// form3
//
this.autoscalebasesize = new system.drawing.size(6, 14);
this.clientsize = new system.drawing.size(292, 266);
this.controls.add(this.button2);
this.controls.add(this.button1);
this.name = "form3";
this.text = "form3";
this.resumelayout(false);

}
#endregion
protected override void onactivated(eventargs e)
{
sendtoback();
}

private void button1_click(object sender, system.eventargs e)
{
messagebox.show("单击测试一!");
}

private void button2_click(object sender, system.eventargs e)
{
messagebox.show("单击测试二!");
}
}
}
好了。大体就是这些了。:)




文章整理:西部数码--专业提供域名注册虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!
相关主题
文章页数:[1] 
Google
热门文章
·经典收藏之 - C++内存管理详解-.NET教程,C#语言
·Master Page 初探-.NET教程,评论及其它
·GDI+编程10个基本技巧-.NET教程,评论及其它
·VB.NET中让Textbox只能输入数字(二)-.NET教程,VB.Net语言
·stl应用小问题-.NET教程,评论及其它
·WIN32中颜色值(COLORREF)与.NET中颜色值(Color)的转换-ASP教程,系统相关
·打造自己的专业图像工具-Visual C++ 2005图像编程系列【三】-.NET教程,C#语言
·.Net中常见问题及解决方法归类-.NET教程,.NET Framework
·Lex和Yacc从入门到精通(3)--一个极其简单的lex和yacc程序-.NET教程,评论及其它
·VB下几个非常有用的函数-.NET教程,VB.Net语言

最新文章
·VC#初学入门:第一个Windows程序
·ASP.NET 2.0-选用DataSet或DataReader
·用.net 处理xmlHttp发送异步请求
·asp.net创建文件夹的IO类的问题
·asp.net 2.0 中加密web.config 文件中的配置节
·关于ASP.NET调用JavaScript的实现
·如何实现ASP.NET网站个性化
·Acegi安全系统的配置-.NET教程,评论及其它
·Spring安全系统:Acegi Security Acegi简介-.NET教程,评论及其它
·Biztalk 开发之 架构和实例的验证-.NET教程,评论及其它




版权申明:本站文章均来自网络,如有侵权,请联系我们,我们收到后立即删除,谢谢!

特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有。
  打印  刷新  关闭
返回首页 |关于我们 | 联系我们 | 付款方式 | 创业联盟 | 虚拟主机 | 资讯中心 | 友情链接 | 网站地图

版权所有 西部数码(www.west263.com)
CopyRight (c) 2002~2006 west263.com all right reserved.
公司地址:四川成都市万和路90号天象大厦4楼 邮编:610031
电话总机:028-86262244 86263048 86263408 86263960 86264018 86267838
售前咨询:总机转201 202 203 204 206 208
售后服务:总机转211 212 213 214
财务咨询:总机转224 223 传真:028-86264041 财务QQ:点击发送消息给对方635483282
售前咨询QQ:点击发送消息给对方2182518 点击发送消息给对方241975952 点击发送消息给对方275026793 点击发送消息给对方408235859
售后服务QQ:点击发送消息给对方17708515 点击发送消息给对方307742704 点击发送消息给对方287976517 点击发送消息给对方363783715
《中华人民共和国增值电信业务经营许可证》编号:川B2-20030065号