人人做人人澡人人爽欧美,国产主播一区二区,久久久精品五月天,羞羞视频在线观看免费

當前位置:蘿卜系統下載站 > 技術開發教程 > 詳細頁面

制作自己的控制臺

制作自己的控制臺

更新時間:2022-07-02 文章作者:未知 信息來源:網絡 閱讀次數:

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

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

溫馨提示:喜歡本站的話,請收藏一下本站!

本類教程下載

系統下載排行

網站地圖xml | 網站地圖html
主站蜘蛛池模板: 长葛市| 灵台县| 韩城市| 西吉县| 长顺县| 天峨县| 舟曲县| 南溪县| 隆德县| 绥江县| 海阳市| 诏安县| 荣成市| 邵武市| 和政县| 东明县| 新巴尔虎左旗| 江达县| 翁牛特旗| 景谷| 合江县| 历史| 东源县| 特克斯县| 涿州市| 徐汇区| 泸溪县| 察隅县| 墨玉县| 乐都县| 团风县| 灌阳县| 白山市| 海安县| 河间市| 嘉禾县| 德惠市| 黄陵县| 平原县| 康保县| 鹤壁市|