?? mainform.cs
字號:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
using System.Text;
namespace Editor
{
/// <summary>
/// Form1 的摘要說明。
/// </summary>
public class MainForm : System.Windows.Forms.Form
{
#region windows controls
private System.Windows.Forms.MainMenu mainMenu;
private System.Windows.Forms.MenuItem menu_File;
private System.Windows.Forms.MenuItem menu_Edit;
private System.Windows.Forms.MenuItem menu_Help;
private System.Windows.Forms.MenuItem menu_FileOpen;
private System.Windows.Forms.MenuItem menu_FileSave;
private System.Windows.Forms.MenuItem menu_FileSaveAs;
private System.Windows.Forms.MenuItem menu_Format;
private System.Windows.Forms.MenuItem menuItem2;
private System.Windows.Forms.MenuItem menu_EditCut;
private System.Windows.Forms.MenuItem menu_EditCopy;
private System.Windows.Forms.MenuItem menu_EditPaste;
private System.Windows.Forms.MenuItem menuItem3;
private System.Windows.Forms.MenuItem menu_EditDel;
private System.Windows.Forms.MenuItem menu_EditSelAll;
private System.Windows.Forms.MenuItem menuItem4;
private System.Windows.Forms.MenuItem menu_EditFind;
private System.Windows.Forms.MenuItem menu_EditReplace;
public System.Windows.Forms.RichTextBox txtMain;
private System.Windows.Forms.MenuItem menuItem5;
private System.Windows.Forms.MenuItem menu_FileExit;
private System.Windows.Forms.MenuItem menu_HelpAbout;
private System.Windows.Forms.MenuItem menu_FileNew;
private System.Windows.Forms.StatusBar mainStatus;
private System.Windows.Forms.StatusBarPanel statusBarSaveTime;
private System.Windows.Forms.OpenFileDialog dlg_openFile;
private System.Windows.Forms.SaveFileDialog dlg_saveFile;
private System.Windows.Forms.FontDialog dlg_font;
private System.Windows.Forms.MenuItem menu_EditUndo;
private System.Windows.Forms.MenuItem menu_EditRedo;
private System.Windows.Forms.MenuItem menu_FormatFont;
private System.Windows.Forms.MenuItem menuItem7;
private System.Windows.Forms.MenuItem menu_EncodeGB;
private System.Windows.Forms.MenuItem menu_EncodeASCII;
private System.Windows.Forms.MenuItem menu_EncodeUTF7;
private System.Windows.Forms.MenuItem menu_EncodeUTF8;
private System.Windows.Forms.MenuItem menu_EncodeUni;
#endregion
#region 定義的field和attribute
private bool IsChanged; // 文檔是否被修改
private bool IsSaved; // 文檔是否被保存過
private Encoding TextEncoding = Encoding.GetEncoding("GB2312");
private SearchAndReplace searchForm;
private string fileName;// 文檔的文件名
public string FileName
{
get
{
if(this.fileName == null)
{
return "無標題";
}
return this.fileName;
}
set
{
this.fileName = value;
}
}
#endregion
/// <summary>
/// 必需的設(shè)計器變量。
/// </summary>
private System.ComponentModel.Container components = null;
public MainForm()
{
//
// Windows 窗體設(shè)計器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 調(diào)用后添加任何構(gòu)造函數(shù)代碼
//
}
/// <summary>
/// 清理所有正在使用的資源。
/// </summary>
protected override void Dispose( bool disposing )
{
if(!AlertSaveFile())
{
return;
}
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗體設(shè)計器生成的代碼
/// <summary>
/// 設(shè)計器支持所需的方法 - 不要使用代碼編輯器修改
/// 此方法的內(nèi)容。
/// </summary>
private void InitializeComponent()
{
this.mainMenu = new System.Windows.Forms.MainMenu();
this.menu_File = new System.Windows.Forms.MenuItem();
this.menu_FileNew = new System.Windows.Forms.MenuItem();
this.menu_FileOpen = new System.Windows.Forms.MenuItem();
this.menu_FileSave = new System.Windows.Forms.MenuItem();
this.menu_FileSaveAs = new System.Windows.Forms.MenuItem();
this.menuItem5 = new System.Windows.Forms.MenuItem();
this.menu_FileExit = new System.Windows.Forms.MenuItem();
this.menu_Edit = new System.Windows.Forms.MenuItem();
this.menu_EditUndo = new System.Windows.Forms.MenuItem();
this.menu_EditRedo = new System.Windows.Forms.MenuItem();
this.menuItem2 = new System.Windows.Forms.MenuItem();
this.menu_EditCut = new System.Windows.Forms.MenuItem();
this.menu_EditCopy = new System.Windows.Forms.MenuItem();
this.menu_EditPaste = new System.Windows.Forms.MenuItem();
this.menu_EditDel = new System.Windows.Forms.MenuItem();
this.menuItem3 = new System.Windows.Forms.MenuItem();
this.menu_EditFind = new System.Windows.Forms.MenuItem();
this.menu_EditReplace = new System.Windows.Forms.MenuItem();
this.menuItem4 = new System.Windows.Forms.MenuItem();
this.menu_EditSelAll = new System.Windows.Forms.MenuItem();
this.menu_Format = new System.Windows.Forms.MenuItem();
this.menu_FormatFont = new System.Windows.Forms.MenuItem();
this.menuItem7 = new System.Windows.Forms.MenuItem();
this.menu_EncodeGB = new System.Windows.Forms.MenuItem();
this.menu_EncodeUni = new System.Windows.Forms.MenuItem();
this.menu_EncodeUTF7 = new System.Windows.Forms.MenuItem();
this.menu_EncodeUTF8 = new System.Windows.Forms.MenuItem();
this.menu_EncodeASCII = new System.Windows.Forms.MenuItem();
this.menu_Help = new System.Windows.Forms.MenuItem();
this.menu_HelpAbout = new System.Windows.Forms.MenuItem();
this.txtMain = new System.Windows.Forms.RichTextBox();
this.mainStatus = new System.Windows.Forms.StatusBar();
this.statusBarSaveTime = new System.Windows.Forms.StatusBarPanel();
this.dlg_openFile = new System.Windows.Forms.OpenFileDialog();
this.dlg_saveFile = new System.Windows.Forms.SaveFileDialog();
this.dlg_font = new System.Windows.Forms.FontDialog();
((System.ComponentModel.ISupportInitialize)(this.statusBarSaveTime)).BeginInit();
this.SuspendLayout();
//
// mainMenu
//
this.mainMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menu_File,
this.menu_Edit,
this.menu_Format,
this.menu_Help});
//
// menu_File
//
this.menu_File.Index = 0;
this.menu_File.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menu_FileNew,
this.menu_FileOpen,
this.menu_FileSave,
this.menu_FileSaveAs,
this.menuItem5,
this.menu_FileExit});
this.menu_File.Text = "文件(&F)";
//
// menu_FileNew
//
this.menu_FileNew.Index = 0;
this.menu_FileNew.Text = "新建文件";
this.menu_FileNew.Click += new System.EventHandler(this.menu_FileNew_Click);
//
// menu_FileOpen
//
this.menu_FileOpen.Index = 1;
this.menu_FileOpen.Text = "打開文件";
this.menu_FileOpen.Click += new System.EventHandler(this.menu_FileOpen_Click);
//
// menu_FileSave
//
this.menu_FileSave.Index = 2;
this.menu_FileSave.Text = "保存";
this.menu_FileSave.Click += new System.EventHandler(this.menu_FileSave_Click);
//
// menu_FileSaveAs
//
this.menu_FileSaveAs.Index = 3;
this.menu_FileSaveAs.Text = "另存為...";
this.menu_FileSaveAs.Click += new System.EventHandler(this.menu_FileSaveAs_Click);
//
// menuItem5
//
this.menuItem5.Index = 4;
this.menuItem5.Text = "-";
//
// menu_FileExit
//
this.menu_FileExit.Index = 5;
this.menu_FileExit.Text = "退出";
this.menu_FileExit.Click += new System.EventHandler(this.menu_FileExit_Click);
//
// menu_Edit
//
this.menu_Edit.Index = 1;
this.menu_Edit.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menu_EditUndo,
this.menu_EditRedo,
this.menuItem2,
this.menu_EditCut,
this.menu_EditCopy,
this.menu_EditPaste,
this.menu_EditDel,
this.menuItem3,
this.menu_EditFind,
this.menu_EditReplace,
this.menuItem4,
this.menu_EditSelAll});
this.menu_Edit.Text = "編輯(&E)";
//
// menu_EditUndo
//
this.menu_EditUndo.Index = 0;
this.menu_EditUndo.Text = "撤銷";
this.menu_EditUndo.Click += new System.EventHandler(this.menu_EditUndo_Click);
//
// menu_EditRedo
//
this.menu_EditRedo.Index = 1;
this.menu_EditRedo.Text = "重復(fù)";
this.menu_EditRedo.Click += new System.EventHandler(this.menu_EditRedo_Click);
//
// menuItem2
//
this.menuItem2.Index = 2;
this.menuItem2.Text = "-";
//
// menu_EditCut
//
this.menu_EditCut.Index = 3;
this.menu_EditCut.Text = "剪切";
this.menu_EditCut.Click += new System.EventHandler(this.menu_EditCut_Click);
//
// menu_EditCopy
//
this.menu_EditCopy.Index = 4;
this.menu_EditCopy.Text = "復(fù)制";
this.menu_EditCopy.Click += new System.EventHandler(this.menu_EditCopy_Click);
//
// menu_EditPaste
//
this.menu_EditPaste.Index = 5;
this.menu_EditPaste.Text = "粘貼";
this.menu_EditPaste.Click += new System.EventHandler(this.menu_EditPaste_Click);
//
// menu_EditDel
//
this.menu_EditDel.Index = 6;
this.menu_EditDel.Text = "刪除";
this.menu_EditDel.Click += new System.EventHandler(this.menu_EditDel_Click);
//
// menuItem3
//
this.menuItem3.Index = 7;
this.menuItem3.Text = "-";
//
// menu_EditFind
//
this.menu_EditFind.Index = 8;
this.menu_EditFind.Text = "查找";
this.menu_EditFind.Click += new System.EventHandler(this.menu_EditFind_Click);
//
// menu_EditReplace
//
this.menu_EditReplace.Index = 9;
this.menu_EditReplace.Text = "替換";
this.menu_EditReplace.Click += new System.EventHandler(this.menu_EditFind_Click);
//
// menuItem4
//
this.menuItem4.Index = 10;
this.menuItem4.Text = "-";
//
// menu_EditSelAll
//
this.menu_EditSelAll.Index = 11;
this.menu_EditSelAll.Text = "全選";
this.menu_EditSelAll.Click += new System.EventHandler(this.menu_EditSelAll_Click);
//
// menu_Format
//
this.menu_Format.Index = 2;
this.menu_Format.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menu_FormatFont,
this.menuItem7});
this.menu_Format.Text = "格式(&O)";
//
// menu_FormatFont
//
this.menu_FormatFont.Index = 0;
this.menu_FormatFont.Text = "字體";
this.menu_FormatFont.Click += new System.EventHandler(this.menu_FormatFont_Click);
//
// menuItem7
//
this.menuItem7.Index = 1;
this.menuItem7.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menu_EncodeGB,
this.menu_EncodeUni,
this.menu_EncodeUTF7,
this.menu_EncodeUTF8,
this.menu_EncodeASCII});
this.menuItem7.Text = "編碼";
//
// menu_EncodeGB
//
this.menu_EncodeGB.Index = 0;
this.menu_EncodeGB.Text = "GB2312";
this.menu_EncodeGB.Click += new System.EventHandler(this.menu_EncodeGB_Click);
//
// menu_EncodeUni
//
this.menu_EncodeUni.Index = 1;
this.menu_EncodeUni.Text = "Unicode";
this.menu_EncodeUni.Click += new System.EventHandler(this.menu_EncodeUni_Click);
//
// menu_EncodeUTF7
//
this.menu_EncodeUTF7.Index = 2;
this.menu_EncodeUTF7.Text = "UTF7";
this.menu_EncodeUTF7.Click += new System.EventHandler(this.menu_EncodeUTF7_Click);
//
// menu_EncodeUTF8
//
this.menu_EncodeUTF8.Index = 3;
this.menu_EncodeUTF8.Text = "UTF8";
this.menu_EncodeUTF8.Click += new System.EventHandler(this.menu_EncodeUTF8_Click);
//
// menu_EncodeASCII
//
this.menu_EncodeASCII.Index = 4;
this.menu_EncodeASCII.Text = "ASCII";
this.menu_EncodeASCII.Click += new System.EventHandler(this.menu_EncodeASCII_Click);
//
// menu_Help
//
this.menu_Help.Index = 3;
this.menu_Help.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menu_HelpAbout});
this.menu_Help.Text = "幫助(&H)";
//
// menu_HelpAbout
//
this.menu_HelpAbout.Index = 0;
this.menu_HelpAbout.Text = "關(guān)于";
this.menu_HelpAbout.Click += new System.EventHandler(this.menu_HelpAbout_Click);
//
// txtMain
//
this.txtMain.AcceptsTab = true;
this.txtMain.AllowDrop = true;
this.txtMain.Location = new System.Drawing.Point(0, 0);
this.txtMain.Name = "txtMain";
this.txtMain.Size = new System.Drawing.Size(408, 256);
this.txtMain.TabIndex = 0;
this.txtMain.Text = "";
this.txtMain.TextChanged += new System.EventHandler(this.txtMain_TextChanged);
//
// mainStatus
//
this.mainStatus.Location = new System.Drawing.Point(0, 261);
this.mainStatus.Name = "mainStatus";
this.mainStatus.Panels.AddRange(new System.Windows.Forms.StatusBarPanel[] {
this.statusBarSaveTime});
this.mainStatus.ShowPanels = true;
this.mainStatus.Size = new System.Drawing.Size(408, 20);
this.mainStatus.TabIndex = 1;
//
// statusBarSaveTime
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -