📄 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 + -