WinForm 小程式 NotePad

來源:互聯網
上載者:User

標籤:

 

運行效果:

 

 

代碼:

 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 FreeNotes12 {13     public partial class NotePad : Form14     {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 }

 

WinForm 小程式 NotePad

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.