📄 main.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
namespace MDICSharp
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class frmMain : System.Windows.Forms.Form
{
private System.Windows.Forms.MainMenu mainMenu1;
private System.Windows.Forms.MenuItem mnuFile;
private System.Windows.Forms.MenuItem mnuFileNew;
private System.Windows.Forms.MenuItem mnuFileOpen;
private System.Windows.Forms.MdiClient mdiClient1;
private System.Windows.Forms.MenuItem mnuFileSave;
private System.Windows.Forms.MenuItem menuItem1;
private System.Windows.Forms.MenuItem mnuFileExit;
private System.Windows.Forms.ImageList imageList1;
private System.ComponentModel.IContainer components;
private System.Windows.Forms.ToolBar toolBar1;
private System.Windows.Forms.ToolBarButton toolBarNewFile;
private System.Windows.Forms.ToolBarButton toolBarExit;
private frmChild fc ;
public frmMain()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(frmMain));
this.mnuFile = new System.Windows.Forms.MenuItem();
this.mnuFileNew = new System.Windows.Forms.MenuItem();
this.mnuFileOpen = new System.Windows.Forms.MenuItem();
this.mnuFileSave = new System.Windows.Forms.MenuItem();
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.mnuFileExit = new System.Windows.Forms.MenuItem();
this.mainMenu1 = new System.Windows.Forms.MainMenu();
this.mdiClient1 = new System.Windows.Forms.MdiClient();
this.imageList1 = new System.Windows.Forms.ImageList(this.components);
this.toolBar1 = new System.Windows.Forms.ToolBar();
this.toolBarNewFile = new System.Windows.Forms.ToolBarButton();
this.toolBarExit = new System.Windows.Forms.ToolBarButton();
this.SuspendLayout();
//
// mnuFile
//
this.mnuFile.Index = 0;
this.mnuFile.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.mnuFileNew,
this.mnuFileOpen,
this.mnuFileSave,
this.menuItem1,
this.mnuFileExit});
this.mnuFile.Text = "File";
//
// mnuFileNew
//
this.mnuFileNew.Index = 0;
this.mnuFileNew.Text = "New";
this.mnuFileNew.Click += new System.EventHandler(this.mnuFileNew_Click);
//
// mnuFileOpen
//
this.mnuFileOpen.Index = 1;
this.mnuFileOpen.Text = "Open";
this.mnuFileOpen.Click += new System.EventHandler(this.mnuFileOpen_Click);
//
// mnuFileSave
//
this.mnuFileSave.Enabled = false;
this.mnuFileSave.Index = 2;
this.mnuFileSave.Text = "Save";
this.mnuFileSave.Click += new System.EventHandler(this.mnuFileSave_Click);
//
// menuItem1
//
this.menuItem1.Index = 3;
this.menuItem1.Text = "--------";
//
// mnuFileExit
//
this.mnuFileExit.Index = 4;
this.mnuFileExit.Text = "Exit";
this.mnuFileExit.Click += new System.EventHandler(this.mnuFileExit_Click);
//
// mainMenu1
//
this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.mnuFile});
//
// mdiClient1
//
this.mdiClient1.Dock = System.Windows.Forms.DockStyle.Fill;
this.mdiClient1.Location = new System.Drawing.Point(0, 42);
this.mdiClient1.Name = "mdiClient1";
this.mdiClient1.TabIndex = 0;
//
// imageList1
//
this.imageList1.ImageSize = new System.Drawing.Size(16, 16);
this.imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.ImageStream")));
this.imageList1.TransparentColor = System.Drawing.Color.Transparent;
//
// toolBar1
//
this.toolBar1.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {
this.toolBarNewFile,
this.toolBarExit});
this.toolBar1.ButtonSize = new System.Drawing.Size(56, 36);
this.toolBar1.DropDownArrows = true;
this.toolBar1.ImageList = this.imageList1;
this.toolBar1.Location = new System.Drawing.Point(0, 0);
this.toolBar1.Name = "toolBar1";
this.toolBar1.ShowToolTips = true;
this.toolBar1.Size = new System.Drawing.Size(736, 42);
this.toolBar1.TabIndex = 1;
this.toolBar1.TabStop = true;
this.toolBar1.Tag = "";
this.toolBar1.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.toolBar1_ButtonClick);
//
// toolBarNewFile
//
this.toolBarNewFile.ImageIndex = 4;
this.toolBarNewFile.Text = "NewFile";
//
// toolBarExit
//
this.toolBarExit.ImageIndex = 5;
this.toolBarExit.Text = "EXIT";
//
// frmMain
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(736, 433);
this.Controls.Add(this.toolBar1);
this.Controls.Add(this.mdiClient1);
this.IsMdiContainer = true;
this.Menu = this.mainMenu1;
this.Name = "frmMain";
this.Text = "Main";
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new frmMain());
}
private void mnuFileNew_Click(object sender, System.EventArgs e)
{
mnuFileSave.Enabled = true;
frmChild fc = new frmChild();
fc.MdiParent = this;
//Document doc1 = new Document();
// fc.AddDocument(doc1);
//doc1.AttachView(fc); //shail
fc.Show();
}
private void mnuWindowNew_Click(object sender, System.EventArgs e)
{
try
{
frmChild fc = new frmChild();
fc.MdiParent = this;
// get the doc reference from active child window
frmChild factive = (frmChild) this.ActiveMdiChild;
Document doc1 = (Document) factive.GetDocument();
fc.AddDocument(doc1);
//shail doc1.AttachView(fc);
fc.Show();}
catch{}
}
private void mnuFileSave_Click(object sender, System.EventArgs e)
{
try
{
// get the doc reference from active child window
frmChild factive = (frmChild) this.ActiveMdiChild;
factive.miSave_Click(null,null);}
catch{}
}
private void mnuFileOpen_Click(object sender, System.EventArgs e)
{
mnuFileSave.Enabled =true;
//frmChild fc = new frmChild();
fc = new frmChild();
fc.MdiParent = this;
fc.miOpen_Click(null,null);
fc.Show();
fc.OnUpdate();
}
private void toolBar1_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
{
switch (toolBar1.Buttons.IndexOf(e.Button))
{
case 0 :
mnuFileNew_Click(null, null);
break;
case 1 :
mnuFileExit_Click(null,null);
break;
}
}
private void mnuFileExit_Click(object sender, System.EventArgs e)
{
//mnuFileSave_Click(null,null);
PromptSave();
Application.Exit();
}
private void PromptSave()
{
string question;
question = "Do you want to Save the Changes Made ?? ";
try
{
// if(fc.Enabled == true)
if (MessageBox.Show(question,"Save File?", MessageBoxButtons.YesNo) == DialogResult.Yes)
mnuFileSave_Click(null,null);}
catch(Exception e)
{
MessageBox.Show(e.ToString());
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -