国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > 綜合 > 正文

制作自己的控制臺

2024-07-21 02:19:49
字體:
來源:轉載
供稿:網友

日前,有人問道:如何把一個子窗口設置為主窗口的“控制臺”,也就是說,要在它上面進行一些系統性的操作。比如:功能的劃分,子功能的調用。如果這樣做出來的話,那么,它就具有操作直觀性了。
好了,廢話不說了,進入正題吧:)

我們用一種方法:加一個子窗口,并設置該子窗口為最底層,在該子窗口上加一個可拉伸的圖片框。當該子窗口被激活,就把它設置為最底層。并且,不允許用戶關閉它,就可以了。
具體方法:
加載一個子窗口(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("單擊測試二!");
}
}
}
好了。大體就是這些了。:)



發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 姚安县| 利辛县| 竹山县| 和政县| 桃源县| 英德市| 绿春县| 仲巴县| 长春市| 新干县| 临邑县| 黔江区| 永德县| 陕西省| 吴桥县| 墨脱县| 郓城县| 同仁县| 阿尔山市| 曲周县| 荆州市| 玛沁县| 广灵县| 松阳县| 五莲县| 从江县| 阿荣旗| 同江市| 齐齐哈尔市| 特克斯县| 浦城县| 廉江市| 阳朔县| 修武县| 彩票| 普宁市| 平南县| 梓潼县| 五台县| 抚宁县| 静宁县|