求C#设计记事本步骤和源代码。大神们帮帮忙
1个回答
展开全部
我给你一下代码,可能没有注释,你自己理解下吧 说白了就是两个控件加文件流的应用腊行,你自己多想想吧 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.IO; using System.Drawing.Printing; namespace 记事本 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void 新建NToolStripMenuItem_Click(object sender, EventArgs e) { if (MessageBox.Show("保存当前文本?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { 保存SToolStripMenuItem_Click(null, null); textBox1.Clear(); } else { textBox1.Clear(); } } private void 新岁埋建NToolStripButton_Click(object sender, EventArgs e) { 新建NToolStripMenuItem_Click(null,null); } private void Form1_Load(object sender, EventArgs e) { skinEngine1.SkinFile = "vista1_green.ssk"; this.countlabel.Text = "已经输入" + this.textBox1.Text.Length + "个字"; } private void textBox1_TextChanged(object sender, EventArgs e) { this.countlabel.Text = "已经输入" + this.textBox1.Text.Length + "个字符"; } private void 打开OToolStripMenuItem_Click(object sender, EventArgs e) { DialogResult result = dlgOpen.ShowDialog(); if (result != System.Windows.Forms.DialogResult.OK) { return; } textBox1.Text = File.ReadAllText(dlgOpen.FileName); } private void 保存SToolStripMenuItem_Click(object sender, EventArgs e) { DialogResult result = dlgSave.ShowDialog(); if (result != System.Windows.Forms.DialogResult.OK) { return; } StreamWriter sw = File.CreateText(dlgSave.FileName); sw.Write(textBox1.Text); sw.Close(); } private void 字体颜色SToolStripMenuItem_Click(object sender, EventArgs e) { DialogResult result = colorDialog1.ShowDialog(); if (result != System.Windows.Forms.DialogResult.OK) { return; } textBox1.ForeColor = colorDialog1.Color ; } private void 字轮雀哗体大小FToolStripMenuItem_Click(object sender, EventArgs e) { DialogResult result = fontDialog1.ShowDialog(); if (result != System.Windows.Forms.DialogResult.OK) { return; } textBox1.Font = fontDialog1.Font; } private void 打开文档ToolStripMenuItem_Click(object sender, EventArgs e) { 打开OToolStripMenuItem_Click(null, null); } private void 撤消UToolStripMenuItem_Click(object sender, EventArgs e) { this.textBox1.Undo(); } private void 剪切TToolStripMenuItem_Click(object sender, EventArgs e) { if (textBox1.SelectedText.Length > 0) { this.textBox1.Cut(); } } private void 复制CToolStripMenuItem_Click(object sender, EventArgs e) { if (textBox1.SelectedText.Equals("")) return; Clipboard.SetDataObject(textBox1.SelectedText, true); } private void 粘贴PToolStripMenuItem_Click(object sender, EventArgs e) { if (Clipboard.GetDataObject().GetDataPresent(DataFormats.Text)) { this.粘贴PToolStripMenuItem.Enabled = true; this.textBox1.Paste(); } else { this.粘贴PToolStripMenuItem.Enabled = false; } } } }
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询