C#實(shí)現(xiàn)簡(jiǎn)單文本編輯器
本文實(shí)例為大家分享了C#實(shí)現(xiàn)簡(jiǎn)單文本編輯器的具體代碼,供大家參考,具體內(nèi)容如下
建立一個(gè)窗體文件,實(shí)現(xiàn)對(duì)文件的編輯保存和對(duì)txt文件的打開(kāi)
界面設(shè)計(jì):
程序源代碼:
//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 菜單選項(xiàng) 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 菜單選項(xiàng) 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 菜單選項(xiàng) private void exitToolStripMenuItem_Click(object sender, EventArgs e) { Close(); } //About 菜單選項(xiàng) 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) { } } }
運(yùn)行截圖
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- C# WebApi Get請(qǐng)求方式傳遞實(shí)體參數(shù)的方法示例
- 詳解C#中的session用法
- C#讀取Excel到DataTable的方法示例
- C# 填充Excel圖表、圖例背景色的實(shí)例代碼
- C#/.NET使用git命令行來(lái)操作git倉(cāng)庫(kù)的方法示例
- C#實(shí)現(xiàn)簡(jiǎn)單記事本程序
- 詳解C#開(kāi)發(fā)Android應(yīng)用程序的流程
- C#實(shí)現(xiàn)記事本查找與替換功能
- C#用記事本編寫(xiě)簡(jiǎn)單WinForm窗體程序
- C#中#define后面只加一個(gè)參數(shù)的解釋
相關(guān)文章
C#開(kāi)發(fā)的人臉左右相似度計(jì)算軟件源碼分析
這篇文章主要介紹了C#開(kāi)發(fā)的人臉左右相似度計(jì)算軟件,較為詳細(xì)的分析了相似度計(jì)算的相關(guān)原理與具體實(shí)現(xiàn)技巧,需要的朋友可以參考下2015-04-04C#讀取XML中元素和屬性值的實(shí)現(xiàn)代碼
用C#讀取xml有很多方式,這里我就先使用XmlDocument讀取Xml,用一段代碼遍歷所有元素,并打印student的所有屬性和子節(jié)點(diǎn)的值2013-04-04C#實(shí)現(xiàn)判斷操作系統(tǒng)是否為Win8以上版本
這篇文章主要介紹了C#實(shí)現(xiàn)判斷操作系統(tǒng)是否為Win8以上版本,本文講解了利用C#獲取OS的版本號(hào)、利用反射獲取當(dāng)前正在運(yùn)行的程序的版本信息、 利用C#判斷當(dāng)前操作系統(tǒng)是否為Win8系統(tǒng)等內(nèi)容,需要的朋友可以參考下2015-06-06C#實(shí)現(xiàn)讀取txt通用的方法小結(jié)
這篇文章主要為大家詳細(xì)介紹了C#讀取txt通用的方法,兼容所有的UTF-8、Unicode(Little Endian)、BigEndianUnicode,有需要的小伙伴可以了解下2024-01-01C#在Windows窗體控件實(shí)現(xiàn)內(nèi)容拖放(DragDrop)功能
這篇文章介紹了C#在Windows窗體控件實(shí)現(xiàn)內(nèi)容拖放(DragDrop)的功能,文中通過(guò)示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-05-05