C#實現(xiàn)簡單文本編輯器
更新時間:2019年04月11日 08:33:45 作者:xujinshan361
這篇文章主要為大家詳細介紹了C#實現(xiàn)簡單文本編輯器,具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了C#實現(xiàn)簡單文本編輯器的具體代碼,供大家參考,具體內(nèi)容如下
建立一個窗體文件,實現(xiàn)對文件的編輯保存和對txt文件的打開
界面設計:
程序源代碼:
//form1.cs 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 Txt_EditApp { public partial class Form1 : Form { public Form1() { InitializeComponent(); } //Open file 菜單選項 private void openFileToolStripMenuItem_Click(object sender, EventArgs e) { openFileDialog1.Filter = "txt files(*.txt)|*.txt"; if(openFileDialog1.ShowDialog()==DialogResult.OK) { richTextBox1.LoadFile(openFileDialog1.FileName, RichTextBoxStreamType.PlainText); } } //Save file 菜單選項 private void saveFileToolStripMenuItem_Click(object sender, EventArgs e) { saveFileDialog1.Filter = "txt files(*.txt)|*.txt"; if(saveFileDialog1.ShowDialog()==DialogResult.OK) { richTextBox1.SaveFile(saveFileDialog1.FileName, RichTextBoxStreamType.PlainText); } } //exit file 菜單選項 private void exitToolStripMenuItem_Click(object sender, EventArgs e) { Close(); } //About 菜單選項 private void aboutToolStripMenuItem_Click(object sender, EventArgs e) { Form2 frm = new Form2(); frm.ShowDialog(); } } } //form2.cs 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 Txt_EditApp { public partial class Form2 : Form { public Form2() { InitializeComponent(); } private void label2_Click(object sender, EventArgs e) { } } }
運行截圖
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
C#實現(xiàn)判斷操作系統(tǒng)是否為Win8以上版本
這篇文章主要介紹了C#實現(xiàn)判斷操作系統(tǒng)是否為Win8以上版本,本文講解了利用C#獲取OS的版本號、利用反射獲取當前正在運行的程序的版本信息、 利用C#判斷當前操作系統(tǒng)是否為Win8系統(tǒng)等內(nèi)容,需要的朋友可以參考下2015-06-06C#在Windows窗體控件實現(xiàn)內(nèi)容拖放(DragDrop)功能
這篇文章介紹了C#在Windows窗體控件實現(xiàn)內(nèi)容拖放(DragDrop)的功能,文中通過示例代碼介紹的非常詳細。對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-05-05