C#编写简单的记事本
用C#编写记事本首先要引用与文件读写有关的命名空间using System.IO;
记事本的撤销,复制,粘贴,剪切,删除,字体,颜色等实现起来比较简单,只要几句代码:
private void 剪切ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (textBox1.SelectionLength != 0)
{
textBox1.Cut();
}
}
private void 复制CToolStripMenuItem_Click(object sender, EventArgs e)
{
if (textBox1.SelectionLength != 0)
{
textBox1.Copy();
}
}
private void 粘贴PToolStripMenuItem_Click(object sender, EventArgs e)
{
if(Clipboard.GetText().ToString() != "") //剪贴板里有文本
textBox1.Paste();
}
}
private void 撤销ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (textBox1.CanUndo == true) //文本可以撤销
{
textBox1.Undo();
textBox1.ClearUndo(); //消除最近的撤销信息
}
}
private void 全选ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (textBox1.Text != string.Empty)
{
textBox1.SelectAll();
}
}
private void 删除ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (textBox1.SelectedText != string.Empty)
{
textBox1.SelectedText = string.Empty;
}
}
private void 时间日期ToolStripMenuItem_Click(object sender, EventArgs e)
{
textBox1.Text =textBox1.Text + DateTime.Now.ToString();
}
private void 字体ToolStripMenuItem_Click(object sender, EventArgs e)