运行效果:
代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms; namespace FreeNotes
{
public partial class NotePad : Form
{
public NotePad()
{
InitializeComponent();
} /// <summary>
/// 打开文件事件
/// </summary>
private void btn_Open_Click(object sender, EventArgs e)
{
OpenFileDialog of = new OpenFileDialog(); of.DefaultExt = "*.rtf"; of.Filter = "rtf文件(*.rtf)|*.rtf|所有文件(*.*)|*.*"; if (of.ShowDialog() == DialogResult.OK && of.FileName.Length > )
{
richTextBox1.LoadFile(of.FileName, RichTextBoxStreamType.RichText);
}
} /// <summary>
/// 保存文件事件
/// </summary>
private void btn_Save_Click(object sender, EventArgs e)
{
SaveFileDialog sa = new SaveFileDialog(); sa.Title = "保存"; sa.FileName = "*.rtf"; sa.Filter = "rtf文件(*.rtf)|*.rtf|所有文件(*.*)|*.*"; sa.DefaultExt = "*.rtf"; if (sa.ShowDialog() == DialogResult.OK && sa.FileName.Length > )
{
richTextBox1.SaveFile(sa.FileName, RichTextBoxStreamType.RichText);
}
} /// <summary>
/// 字体事件
/// </summary>
private void btn_Font_Click(object sender, EventArgs e)
{
FontDialog fda = new FontDialog(); fda.ShowColor = true; if (fda.ShowDialog() != DialogResult.Cancel)
{
richTextBox1.SelectionFont = fda.Font;
richTextBox1.SelectionColor = fda.Color;
}
} /// <summary>
/// 清空文本事件
/// </summary>
private void btn_Clear_Click(object sender, EventArgs e)
{
richTextBox1.Clear();
}
}
}