C# Main point of a NotePad

11月16日(星期五)

 

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
namespace prjNotePad
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
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 调用后添加任何构造函数代码
//
}

/// <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.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

/// <summary>
/// 应用程序的主入口点。
/// </summary>
[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<s.Length;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<sss.Length;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)
{

}

}
}

 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值