C# Main point of a NotePad
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
namespace prjNotePad
{
///
/// Form1 的摘要說明。
///
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.MainMenu mainMenu1;
private System.Windows.Forms.MenuItem menuItem1;
private System.Windows.Forms.MenuItem menuItem2;
private System.Windows.Forms.MenuItem menuItem3;
private System.Windows.Forms.MenuItem menuItem4;
private System.Windows.Forms.MenuItem menuItem5;
private System.Windows.Forms.MenuItem menuItem6;
private System.Windows.Forms.MenuItem menuItem7;
private System.Windows.Forms.MenuItem menuItem8;
private System.Windows.Forms.MenuItem menuItem9;
private System.Windows.Forms.MenuItem menuItem10;
private System.Windows.Forms.MenuItem menuItem11;
private System.Windows.Forms.MenuItem menuItem13;
private System.Windows.Forms.MenuItem menuItem14;
private System.Windows.Forms.MenuItem menuItem15;
private System.Windows.Forms.MenuItem menuItem16;
private System.Windows.Forms.MenuItem menuItem17;
private System.Windows.Forms.MenuItem menuItem18;
private System.Windows.Forms.MenuItem menuItem19;
private System.Windows.Forms.MenuItem menuItem20;
private System.Windows.Forms.MenuItem menuItem21;
private System.Windows.Forms.MenuItem menuItem22;
private System.Windows.Forms.MenuItem menuItem23;
private System.Windows.Forms.MenuItem menuItem24;
private System.Windows.Forms.MenuItem menuItem25;
private System.Windows.Forms.MenuItem menuItem26;
private System.Windows.Forms.MenuItem menuItem12;
private System.Windows.Forms.MenuItem menuItem27;
private System.Windows.Forms.MenuItem menuItem28;
private System.Windows.Forms.MenuItem menuItem29;
private System.Windows.Forms.MenuItem menuItem30;
private System.Windows.Forms.TextBox txtMain;
private System.Windows.Forms.ContextMenu contextMenu1;
private MenuItem menuItem31;
private IContainer components;
public Form1()
{
//
// Windows 窗體設計器支援所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 呼叫後新增任何建構函式程式碼
//
}
///
/// 清理所有正在使用的資源。
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗體設計器生成的程式碼
///
/// 設計器支援所需的方法 - 不要使用程式碼編輯器修改
/// 此方法的內容。
///
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
this.mainMenu1 = new System.Windows.Forms.MainMenu(this.components);
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.menuItem2 = new System.Windows.Forms.MenuItem();
this.menuItem3 = new System.Windows.Forms.MenuItem();
this.menuItem4 = new System.Windows.Forms.MenuItem();
this.menuItem5 = new System.Windows.Forms.MenuItem();
this.menuItem6 = new System.Windows.Forms.MenuItem();
this.menuItem7 = new System.Windows.Forms.MenuItem();
this.menuItem8 = new System.Windows.Forms.MenuItem();
this.menuItem9 = new System.Windows.Forms.MenuItem();
this.menuItem11 = new System.Windows.Forms.MenuItem();
this.menuItem13 = new System.Windows.Forms.MenuItem();
this.menuItem14 = new System.Windows.Forms.MenuItem();
this.menuItem15 = new System.Windows.Forms.MenuItem();
this.menuItem16 = new System.Windows.Forms.MenuItem();
this.menuItem17 = new System.Windows.Forms.MenuItem();
this.menuItem18 = new System.Windows.Forms.MenuItem();
this.menuItem19 = new System.Windows.Forms.MenuItem();
this.menuItem20 = new System.Windows.Forms.MenuItem();
this.menuItem21 = new System.Windows.Forms.MenuItem();
this.menuItem22 = new System.Windows.Forms.MenuItem();
this.menuItem23 = new System.Windows.Forms.MenuItem();
this.menuItem24 = new System.Windows.Forms.MenuItem();
this.menuItem25 = new System.Windows.Forms.MenuItem();
this.menuItem26 = new System.Windows.Forms.MenuItem();
this.menuItem10 = new System.Windows.Forms.MenuItem();
this.menuItem12 = new System.Windows.Forms.MenuItem();
this.menuItem27 = new System.Windows.Forms.MenuItem();
this.menuItem28 = new System.Windows.Forms.MenuItem();
this.menuItem29 = new System.Windows.Forms.MenuItem();
this.menuItem30 = new System.Windows.Forms.MenuItem();
this.txtMain = new System.Windows.Forms.TextBox();
this.contextMenu1 = new System.Windows.Forms.ContextMenu();
this.menuItem31 = new System.Windows.Forms.MenuItem();
this.SuspendLayout();
//
// mainMenu1
//
this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem1,
this.menuItem11,
this.menuItem10,
this.menuItem28});
//
// menuItem1
//
this.menuItem1.Index = 0;
this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem2,
this.menuItem3,
this.menuItem4,
this.menuItem5,
this.menuItem6,
this.menuItem7,
this.menuItem8,
this.menuItem9});
this.menuItem1.Text = "檔案(&F)";
//
// menuItem2
//
this.menuItem2.Index = 0;
this.menuItem2.Shortcut = System.Windows.Forms.Shortcut.CtrlN;
this.menuItem2.Text = "新建(&N)";
this.menuItem2.Click += new System.EventHandler(this.menuItem2_Click);
//
// menuItem3
//
this.menuItem3.Index = 1;
this.menuItem3.Shortcut = System.Windows.Forms.Shortcut.CtrlO;
this.menuItem3.Text = "開啟(&O)...";
this.menuItem3.Click += new System.EventHandler(this.menuItem3_Click);
//
// menuItem4
//
this.menuItem4.Index = 2;
this.menuItem4.Shortcut = System.Windows.Forms.Shortcut.CtrlS;
this.menuItem4.Text = "儲存(&S)";
this.menuItem4.Click += new System.EventHandler(this.menuItem4_Click);
//
// menuItem5
//
this.menuItem5.Index = 3;
this.menuItem5.Text = "另存為(A)...";
this.menuItem5.Click += new System.EventHandler(this.menuItem5_Click);
//
// menuItem6
//
this.menuItem6.Index = 4;
this.menuItem6.Text = "-";
//
// menuItem7
//
this.menuItem7.Index = 5;
this.menuItem7.Text = "頁面設定(&U)";
this.menuItem7.Click += new System.EventHandler(this.menuItem7_Click);
//
// menuItem8
//
this.menuItem8.Index = 6;
this.menuItem8.Shortcut = System.Windows.Forms.Shortcut.CtrlP;
this.menuItem8.Text = "列印(&P)";
//
// menuItem9
//
this.menuItem9.Index = 7;
this.menuItem9.Text = "退出(&X)";
this.menuItem9.Click += new System.EventHandler(this.menuItem9_Click);
//
// menuItem11
//
this.menuItem11.Index = 1;
this.menuItem11.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem13,
this.menuItem14,
this.menuItem15,
this.menuItem16,
this.menuItem17,
this.menuItem18,
this.menuItem19,
this.menuItem20,
this.menuItem21,
this.menuItem22,
this.menuItem23,
this.menuItem24,
this.menuItem25,
this.menuItem26});
this.menuItem11.Text = "編輯(&E)";
//
// menuItem13
//
this.menuItem13.Index = 0;
this.menuItem13.Shortcut = System.Windows.Forms.Shortcut.CtrlZ;
this.menuItem13.Text = "撤銷(&U)";
this.menuItem13.Click += new System.EventHandler(this.menuItem13_Click);
//
// menuItem14
//
this.menuItem14.Index = 1;
this.menuItem14.Text = "-";
//
// menuItem15
//
this.menuItem15.Index = 2;
this.menuItem15.Shortcut = System.Windows.Forms.Shortcut.CtrlX;
this.menuItem15.Text = "剪下(&T)";
this.menuItem15.Click += new System.EventHandler(this.menuItem15_Click);
//
// menuItem16
//
this.menuItem16.Index = 3;
this.menuItem16.Shortcut = System.Windows.Forms.Shortcut.CtrlC;
this.menuItem16.Text = "複製(&C)";
this.menuItem16.Click += new System.EventHandler(this.menuItem16_Click);
//
// menuItem17
//
this.menuItem17.Index = 4;
this.menuItem17.Shortcut = System.Windows.Forms.Shortcut.CtrlV;
this.menuItem17.Text = "貼上(&P)";
this.menuItem17.Click += new System.EventHandler(this.menuItem17_Click);
//
// menuItem18
//
this.menuItem18.Index = 5;
this.menuItem18.Shortcut = System.Windows.Forms.Shortcut.Del;
this.menuItem18.Text = "刪除(&D)";
this.menuItem18.Click += new System.EventHandler(this.menuItem18_Click);
//
// menuItem19
//
this.menuItem19.Index = 6;
this.menuItem19.Text = "-";
//
// menuItem20
//
this.menuItem20.Index = 7;
this.menuItem20.Shortcut = System.Windows.Forms.Shortcut.CtrlF;
this.menuItem20.Text = "查詢(&F)";
this.menuItem20.Click += new System.EventHandler(this.menuItem20_Click);
//
// menuItem21
//
this.menuItem21.Index = 8;
this.menuItem21.Shortcut = System.Windows.Forms.Shortcut.F3;
this.menuItem21.Text = "查詢下一個(&N)";
//
// menuItem22
//
this.menuItem22.Index = 9;
this.menuItem22.Shortcut = System.Windows.Forms.Shortcut.CtrlH;
this.menuItem22.Text = "替換(&R)";
this.menuItem22.Click += new System.EventHandler(this.menuItem22_Click);
//
// menuItem23
//
this.menuItem23.Index = 10;
this.menuItem23.Shortcut = System.Windows.Forms.Shortcut.CtrlG;
this.menuItem23.Text = "轉到(&G)";
//
// menuItem24
//
this.menuItem24.Index = 11;
this.menuItem24.Text = "-";
//
// menuItem25
//
this.menuItem25.Index = 12;
this.menuItem25.Shortcut = System.Windows.Forms.Shortcut.CtrlA;
this.menuItem25.Text = "全選(&A)";
//
// menuItem26
//
this.menuItem26.Index = 13;
this.menuItem26.Shortcut = System.Windows.Forms.Shortcut.F5;
this.menuItem26.Text = "日期/時間(&D)";
this.menuItem26.Click += new System.EventHandler(this.menuItem26_Click);
//
// menuItem10
//
this.menuItem10.Index = 2;
this.menuItem10.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem12,
this.menuItem27});
this.menuItem10.Text = "格式(&O)";
//
// menuItem12
//
this.menuItem12.Index = 0;
this.menuItem12.Text = "自動換行(&W)";
//
// menuItem27
//
this.menuItem27.Index = 1;
this.menuItem27.Text = "字型(F)...";
//
// menuItem28
//
this.menuItem28.Index = 3;
this.menuItem28.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem29,
this.menuItem30});
this.menuItem28.Text = "幫助(&H)";
//
// menuItem29
//
this.menuItem29.Index = 0;
this.menuItem29.Text = "幫助主題(H)";
//
// menuItem30
//
this.menuItem30.Index = 1;
this.menuItem30.Text = "關於記事本(A)";
this.menuItem30.Click += new System.EventHandler(this.menuItem30_Click);
//
// txtMain
//
this.txtMain.Dock = System.Windows.Forms.DockStyle.Fill;
this.txtMain.Location = new System.Drawing.Point(0, 0);
this.txtMain.Multiline = true;
this.txtMain.Name = "txtMain";
this.txtMain.Size = new System.Drawing.Size(568, 393);
this.txtMain.TabIndex = 0;
this.txtMain.TextChanged += new System.EventHandler(this.txtMain_TextChanged);
//
// contextMenu1
//
this.contextMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem31});
this.contextMenu1.Popup += new System.EventHandler(this.contextMenu1_Popup);
//
// menuItem31
//
this.menuItem31.Index = 0;
this.menuItem31.Text = "撤銷(&U)";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(568, 393);
this.Controls.Add(this.txtMain);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.IsMdiContainer = true;
this.MaximizeBox = false;
this.Menu = this.mainMenu1;
this.Name = "Form1";
this.Text = "記事本";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
///
/// 應用程式的主入口點。
///
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void menuItem7_Click(object sender, System.EventArgs e)
{
}
String filename="";
private void menuItem2_Click(object sender, System.EventArgs e)
{
this.txtMain.Text="";
this.filename="";
}
private void txtMain_TextChanged(object sender, System.EventArgs e)
{
}
private void menuItem3_Click(object sender, System.EventArgs e)
{
OpenFileDialog ofd= new OpenFileDialog();
DialogResult dr=ofd.ShowDialog();
if(dr==DialogResult.Cancel)
{
return;
}
String file=ofd.FileName;
FileInfo fi=new FileInfo(file);
this.Text=fi.Name+"-記事本";
StreamReader sr=new StreamReader(fi.FullName,System.Text.Encoding.GetEncoding("gb2312"));
while(true)
{
String line=sr.ReadLine();
if(line==null)
{
break;
}
if(line.Trim()=="")
{
//換行如果為空行
}
this.txtMain.Text+=line+"rn";
}
sr.Close();
}
private void menuItem4_Click(object sender, System.EventArgs e)
{
if(filename=="")
{
SaveFileDialog sfd=new SaveFileDialog();
DialogResult dr=sfd.ShowDialog();
if(dr==DialogResult.Cancel)
{
return;
}
String savepath=sfd.FileName;
this.filename=sfd.FileName;
FileInfo fi=new FileInfo(savepath);
if(fi.Exists==false)
{
fi.Create();
}
StreamWriter sw=new StreamWriter(fi.FullName+".txt");
String [] s=this.txtMain.Lines;
for(int i=0;i
sw.WriteLine(s[i]);
}
sw.Flush();
sw.Close();
}
else
{
FileInfo s=new FileInfo(this.filename);
String [] sss=this.txtMain.Lines;
StreamWriter sw2=new StreamWriter(s.FullName);
for(int q=0;q
sw2.WriteLine(sss[q]);
}
sw2.Flush();
sw2.Close();
}
}
private void menuItem5_Click(object sender, System.EventArgs e)
{
SaveFileDialog sfd=new SaveFileDialog();
DialogResult sr=sfd.ShowDialog();
if(sr==DialogResult.Cancel)
{
return;
}
String saveaspath=sfd.FileName;
}
private void menuItem9_Click(object sender, System.EventArgs e)
{
this.Close();
}
private void contextMenu1_Popup(object sender, System.EventArgs e)
{
}
private void menuItem13_Click(object sender, EventArgs e)
{
this.txtMain.Undo();
}
private void menuItem15_Click(object sender, EventArgs e)
{
this.txtMain.Cut();
}
private void menuItem16_Click(object sender, EventArgs e)
{
this.txtMain.Copy();
}
private void menuItem17_Click(object sender, EventArgs e)
{
this.txtMain.Paste();
}
private void menuItem18_Click(object sender, EventArgs e)
{
this.txtMain.SelectedText = "";
}
private void menuItem20_Click(object sender, EventArgs e)
{
Research frm = new Research();
frm.SendStringEvent += new SendStringHandler(frm_SendStringEvent);
frm.ShowDialog();
}
void frm_SendStringEvent(string s)
{
if (this.txtMain.Text.IndexOf(s) == -1)
{
MessageBox.Show("未能找到您輸入的文章內容"); return;
}
this.txtMain.SelectionLength = s.Length;
this.txtMain.SelectionStart = this.txtMain.Text.IndexOf(s);
}
private void menuItem30_Click(object sender, EventArgs e)
{
frmAbout f = new frmAbout();
f.ShowDialog();
}
private void Form1_Load(object sender, EventArgs e)
{
this.menuItem12.Checked = true;
}
private void menuItem26_Click(object sender, EventArgs e)
{
this.txtMain.SelectedText=DateTime.Now.ToString();
}
private void menuItem22_Click(object sender, EventArgs e)
{
}
}
}
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/10395457/viewspace-982867/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- RequireJs學習筆記之data-main Entry PointUIJS筆記AI
- C#中Main函式後引數的處理C#AI函式
- C#中含有多個Main函式的處理C#AI函式
- RESTORE POINTREST
- JavaScript some pointJavaScript
- activity_main與fragment_mainAIFragment
- 使用Notepad++開發C#,一個複雜點的csscript指令碼C#CSS指令碼
- study critical point and saddle point using Hessian Matrix
- main方法AI
- Main()方法AI
- notepad++ 批次操作
- 把 Notepad++ 打造成一款易用的C#指令碼編輯器C#指令碼
- AS執行main()方法報錯:SourceSet with name ‘main‘ not foundAI
- 存檔mainAI
- 2788647047_mainAI
- Windows Embedded for Point of Service概述Windows
- angular指令實戰-notepadAngular
- HOW TO PRINT FILE TO NOTEPAD IN GUI?GUI
- Notepad++配置備份
- 找不到 main 方法, 請將 main 方法定義為: public static void main(String[] args)AI
- go run main.go undefined? golang main包那點事AIUndefinedGolang
- Windows Embedded for Point of Service 益處Windows
- 收藏What’s the Point of Oracle Checkpoints?Oracle
- tablespace point in time recover (tpitr)
- notepad怎麼寫pythonPython
- 高效的使用 Notepad++ 工具
- notepad++批量頭尾追加
- Notepad++ 大小寫轉換
- Notepad++ 右鍵選單
- HTML <main> 標籤HTMLAI
- if __name__==”__main__”:AI
- if __name__ == ‘__main__‘AI
- if __name__=="__main__":AI
- Java——main函式JavaAI函式
- The Main Features of MySQLAIMySql
- Animal Cotroller文件——MainAI
- Java - 25 main方法JavaAI
- Notepad++ 使用技巧與外掛