记事本代码
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
记事本代码.txt2008太不正常了,一切都不正常!在这个关键时刻,中国男足挺身而出,向全世界证明:中国男足还是正常的!using System;
using System.Collections.Generic;
using ponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Runtime.InteropServices;
namespace Text01
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void 新建NToolStripMenuItem_Click(object sender, EventArgs e)
{
//如果当前文本内容处于修改状态,则提示保存
if (richTextBox1.Modified == true)
{
DialogResult re = MessageBox.Show("文件" + Text +"的内容已改变,需要保存吗?", "保存文件",MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); switch (re)
{
case DialogResult.Yes:
this.新建NToolStripMenuItem_Click(sender, e);
richTextBox1.Clear();
= "";
this.Text = "新建-记事本";
break;
case DialogResult.No:
richTextBox1.Clear();
= "";
this.Text = "新建-记事本";
break;
case DialogResult.Cancel:
break;
}
}
else
{
richTextBox1.Clear();
= "";
this.Text = "新建-记事本";
richTextBox1.Modified = false;
}
// this.richTextBox1.Text = "";
}
private void 打开OToolStripMenuItem_Click(object sender, EventArgs e) {
OpenFileDialog openF = new OpenFileDialog();
openF.Filter = "文本文件(*.rtf)|*.rtf|文本文件(*.txt)|*.txt|所有文件(*.*)|*.*";
if (openF.ShowDialog() == DialogResult.OK)
{
string strFileNmae = openF.FileName;
string strExt = Path.GetExtension(strFileNmae);//对应命名空间System.IO
if (strExt.ToLower() == ".rtf")
{
this.richTextBox1.LoadFile(
@strFileNmae,
RichTextBoxStreamType.RichText);
}
else if (strExt.ToLower() == ".txt")
{
this.richTextBox1.LoadFile(
@strFileNmae,
RichTextBoxStreamType.PlainText);
}
else
{
this.richTextBox1.Text = "系统不支持该类型文件。";
}
}
}
private void 保存SToolStripMenuItem_Click(object sender, EventArgs e) {
SaveFileDialog saveF = new SaveFileDialog();
saveF.Filter = "文本文件(*.rtf)|*.rtf|文本文件(*.txt)|*.txt|所有文件(*.*)|*.*";
saveF.RestoreDirectory = true;
if (saveF.ShowDialog() == DialogResult.OK)
{
string strFileNmae = saveF.FileName;
this.richTextBox1.SaveFile(
strFileNmae, RichTextBoxStreamType.RichText);
}
}
private void 退出XToolStripMenuItem_Click(object sender, EventArgs e) {
Application.Exit();
}
private void 字体FToolStripMenuItem_Click(object sender, EventArgs e) {
FontDialog fontD = new FontDialog();
fontD.ShowColor = true;
fontD.ShowEffects = true;
if (fontD.ShowDialog() == DialogResult.OK)
{
this.richTextBox1.SelectionFont = fontD.Font;
this.richTextBox1.SelectionColor = fontD.Color;
}
}
private void 颜色ToolStripMenuItem_Click(object sender, EventArgs e)
{
ColorDialog colorD = new ColorDialog();
if (colorD.ShowDialog() == DialogResult.OK)
{
this.richTextBox1.SelectionColor = colorD.Color;
}
}
private void 居中ToolStripMenuItem_Click(object sender, EventArgs e)
{
this.richTextBox1.SelectionAlignment =
HorizontalAlignment.Center;