首 页 网络编程
网页制作 图形图象 操作系统 冲浪宝典
软件教学 认证考试

网络安全 网络办公 行业资讯 评测对比
您当前位置:站长天空 -> 网络编程-> C#/CSHARP教程
制作自己的控制台-.NET教程,C#语言
作者:网友供稿 点击:15
推荐
西部数码-全国虚拟主机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.z6688.com/
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!

文章页数:[1] 


放大字体显示 缩小字体显示 打印文章 推荐给朋友
热门文章
·使用C#编写Windows Forms应用程序(转)-.NET教程,Windows开发
·C#学习杂记-.NET教程,C#语言
·将文本格式的文章转换为html/xml格式文本的功能封装到Javabean-JSP教程,Java技巧及代码
·用java小程序applet实现无限级树结构-JSP教程,Java技巧及代码
·《.net编程先锋C#》第一章 C#简介-.NET教程,C#语言
·企业人事信息管理系统1.0-ASP教程,数据库相关
·《.net编程先锋C#》第三章 第一个C#应用程序-.NET教程,C#语言
·《.net编程先锋C#》第二章 理论基础-公用语言 运行环境-.NET教程,C#语言
·Windows应用程序调试必备的--符号文件(Symbols)-.NET教程,评论及其它
·c#反编译微软msdn2003的帮助文档,并将反编译结果保存到一个sqlserver数据库中
最新文章
·vista的新特性:懒人的安全感_windows vista
·photoshop为情侣照片打造韩式梦幻相框_photoshop教程
·专访seobbs站长乐思蜀_站长访谈
·嘟嘟网络陈艺光:诚信是一种信仰_站长访谈
·俺自己黄修源:只问耕耘,不问收获_站长访谈
·李向华:如何提高论坛用户粘性_站长访谈
·给windows vista系统网络和共享中心“换脸”_windows vista
·胡宪东谈搜索优化的实战_站长心得
·网站快速成功的九个步骤_站长心得
·google pr数字背后的含意_google推广
相关主题
  • 制作自己的网络搜索软件_visualbasic教程
  • 制作自己的mp3播放器_visualbasic教程
  • 制作自己的分隔线控件(LineH、LineV)-.NET教程,组件控件开发
  • 西部数码虚拟主机

    友情链接
    CNNIC 西部数码
    万网 自助建站
    虚拟主机 asp空间
    域名注册 域名
    域名申请 主页空间
    论坛空间 网站空间
    国际域名 虚拟空间
    空间租用 DDOS防火墙
    成都主机托管 四川主机托管
    主机租用 服务器租用
    网站目录 自助建站
    虚拟主机 网址大全
    软件下载
    自助链接
    虚拟主机资讯 特价虚拟主机
    版权申明:本站文章均来自网络,如有侵权,请联系我们,我们收到后立即删除,谢谢!
    关于我们:站长天空:专业提供最新的站长资讯、在线教程、虚拟主机权威评测、虚拟主机性能对比、网站制作教程,开发教程,站长工具。包括网页制作教程、冲浪宝典、编程参考、操作系统、软件教学、行业动态等。
    特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有。
    发表评论 打印  刷新     关闭