?? mainform.cs
字號:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace DataServer
{
/// <summary>
/// MainForm 的摘要說明。
/// </summary>
public class MainForm : System.Windows.Forms.Form
{
private System.Windows.Forms.MenuItem mnu_new;
private System.Windows.Forms.MenuItem mnu_open;
private System.Windows.Forms.MenuItem mnu_close;
private System.Windows.Forms.MenuItem mnu_help;
private System.Windows.Forms.MenuItem mnu_about;
private System.Windows.Forms.ToolBar toolBar;
private System.Windows.Forms.ToolBarButton tbnew;
private System.Windows.Forms.ToolBarButton tbopen;
private System.Windows.Forms.ToolBarButton tbclose;
private System.Windows.Forms.MenuItem mnufile;
private System.Windows.Forms.MainMenu MainMenu;
private System.Windows.Forms.ImageList ilMain;
private System.ComponentModel.IContainer components;
public MainForm()
{
//
// 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();
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(MainForm));
this.MainMenu = new System.Windows.Forms.MainMenu();
this.mnufile = new System.Windows.Forms.MenuItem();
this.mnu_new = new System.Windows.Forms.MenuItem();
this.mnu_open = new System.Windows.Forms.MenuItem();
this.mnu_close = new System.Windows.Forms.MenuItem();
this.mnu_help = new System.Windows.Forms.MenuItem();
this.mnu_about = new System.Windows.Forms.MenuItem();
this.toolBar = new System.Windows.Forms.ToolBar();
this.tbnew = new System.Windows.Forms.ToolBarButton();
this.tbopen = new System.Windows.Forms.ToolBarButton();
this.tbclose = new System.Windows.Forms.ToolBarButton();
this.ilMain = new System.Windows.Forms.ImageList(this.components);
this.SuspendLayout();
//
// MainMenu
//
this.MainMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.mnufile,
this.mnu_help});
//
// mnufile
//
this.mnufile.Index = 0;
this.mnufile.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.mnu_new,
this.mnu_open,
this.mnu_close});
this.mnufile.Text = "文件(&O)";
//
// mnu_new
//
this.mnu_new.Index = 0;
this.mnu_new.Text = "新建(&N)";
this.mnu_new.Click += new System.EventHandler(this.mnu_new_Click);
//
// mnu_open
//
this.mnu_open.Index = 1;
this.mnu_open.Text = "打開(&O)";
this.mnu_open.Click += new System.EventHandler(this.mnu_open_Click);
//
// mnu_close
//
this.mnu_close.Index = 2;
this.mnu_close.Text = "關閉(&C)";
this.mnu_close.Click += new System.EventHandler(this.mnu_close_Click);
//
// mnu_help
//
this.mnu_help.Index = 1;
this.mnu_help.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.mnu_about});
this.mnu_help.Text = "幫助(&H)";
//
// mnu_about
//
this.mnu_about.Index = 0;
this.mnu_about.Text = "關于(&A)";
//
// toolBar
//
this.toolBar.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {
this.tbnew,
this.tbopen,
this.tbclose});
this.toolBar.DropDownArrows = true;
this.toolBar.ImageList = this.ilMain;
this.toolBar.Location = new System.Drawing.Point(0, 0);
this.toolBar.Name = "toolBar";
this.toolBar.ShowToolTips = true;
this.toolBar.Size = new System.Drawing.Size(672, 49);
this.toolBar.TabIndex = 0;
this.toolBar.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.toolBar_ButtonClick);
//
// tbnew
//
this.tbnew.ImageIndex = 0;
this.tbnew.Tag = "1";
this.tbnew.Text = " 新 建 ";
//
// tbopen
//
this.tbopen.ImageIndex = 1;
this.tbopen.Tag = "2";
this.tbopen.Text = " 打 開 ";
//
// tbclose
//
this.tbclose.ImageIndex = 3;
this.tbclose.Tag = "3";
this.tbclose.Text = " 關 閉 ";
//
// ilMain
//
this.ilMain.ImageSize = new System.Drawing.Size(24, 24);
this.ilMain.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("ilMain.ImageStream")));
this.ilMain.TransparentColor = System.Drawing.Color.Transparent;
//
// MainForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.BackColor = System.Drawing.SystemColors.Control;
this.ClientSize = new System.Drawing.Size(672, 421);
this.Controls.Add(this.toolBar);
this.IsMdiContainer = true;
this.Menu = this.MainMenu;
this.Name = "MainForm";
this.Text = "MainForm";
this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
this.Load += new System.EventHandler(this.Main_Load);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 應用程序的主入口點。
/// </summary>
[STAThread]
static void Main()
{
if(!DBConnect.Instance().Connect())
{
MessageBox.Show("數據庫連接失敗!");
Application.Exit() ;
return;
}
LoginForm frmLogin = new LoginForm() ;
DialogResult dr ;
dr = frmLogin.ShowDialog() ;
if (dr != DialogResult.OK )
{
Application.Exit() ;
return ;
}
Application.Run(new MainForm());
}
private void Main_Load(object sender, System.EventArgs e)
{
}
private void toolBar_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
{
int iTag = int.Parse(e.Button.Tag.ToString()) ;
switch(iTag)
{
case 1:
mnu_new.PerformClick() ;
break ;
case 2:
mnu_open.PerformClick() ;
break ;
case 3:
mnu_close.PerformClick() ;
break ;
}
}
private void mnu_new_Click(object sender, System.EventArgs e)
{
foreach(Form frm in this.MdiChildren)
{
if (frm is NewForm)
{
frm.BringToFront() ;
return ;
}
}
NewForm newfrm = new NewForm() ;
newfrm.MdiParent = this ;
newfrm.Show() ;
}
private void mnu_open_Click(object sender, System.EventArgs e)
{
foreach(Form frm in this.MdiChildren)
{
if (frm is OpenForm)
{
frm.BringToFront() ;
return ;
}
}
OpenForm newfrm = new OpenForm() ;
newfrm.MdiParent = this ;
newfrm.Show() ;
}
private void mnu_close_Click(object sender, System.EventArgs e)
{
DialogResult result;
result = MessageBox.Show("是否退出系統?","系統提示",MessageBoxButtons.YesNo);
if (result == System.Windows.Forms.DialogResult.Yes)
{
Application.Exit() ;
return ;
}
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -