标签:
运行效果:
代码:
1 using System; 2 using System.Collections.Generic; 3 using System.ComponentModel; 4 using System.Data; 5 using System.Drawing; 6 using System.Linq; 7 using System.Text; 8 using System.Threading.Tasks; 9 using System.Windows.Forms; 10 11 namespace FreeNotes 12 { 13 public partial class NotePad : Form 14 { 15 public NotePad() 16 { 17 InitializeComponent(); 18 } 19 20 /// <summary> 21 /// 打开文件事件 22 /// </summary> 23 private void btn_Open_Click(object sender, EventArgs e) 24 { 25 OpenFileDialog of = new OpenFileDialog(); 26 27 of.DefaultExt = "*.rtf"; 28 29 of.Filter = "rtf文件(*.rtf)|*.rtf|所有文件(*.*)|*.*"; 30 31 if (of.ShowDialog() == DialogResult.OK && of.FileName.Length > 0) 32 { 33 richTextBox1.LoadFile(of.FileName, RichTextBoxStreamType.RichText); 34 } 35 } 36 37 /// <summary> 38 /// 保存文件事件 39 /// </summary> 40 private void btn_Save_Click(object sender, EventArgs e) 41 { 42 SaveFileDialog sa = new SaveFileDialog(); 43 44 sa.Title = "保存"; 45 46 sa.FileName = "*.rtf"; 47 48 sa.Filter = "rtf文件(*.rtf)|*.rtf|所有文件(*.*)|*.*"; 49 50 sa.DefaultExt = "*.rtf"; 51 52 if (sa.ShowDialog() == DialogResult.OK && sa.FileName.Length > 0) 53 { 54 richTextBox1.SaveFile(sa.FileName, RichTextBoxStreamType.RichText); 55 } 56 } 57 58 /// <summary> 59 /// 字体事件 60 /// </summary> 61 private void btn_Font_Click(object sender, EventArgs e) 62 { 63 FontDialog fda = new FontDialog(); 64 65 fda.ShowColor = true; 66 67 if (fda.ShowDialog() != DialogResult.Cancel) 68 { 69 richTextBox1.SelectionFont = fda.Font; 70 richTextBox1.SelectionColor = fda.Color; 71 } 72 } 73 74 /// <summary> 75 /// 清空文本事件 76 /// </summary> 77 private void btn_Clear_Click(object sender, EventArgs e) 78 { 79 richTextBox1.Clear(); 80 } 81 } 82 }
标签:
原文地址:http://www.cnblogs.com/KTblog/p/4394089.html