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)文章
VS2012 未找到與約束ContractName匹配的導(dǎo)出
這篇文章主要介紹了在更新的windows補(bǔ)丁后,Visual Studio 用戶可能無(wú)法打開(kāi)或創(chuàng)建 C++ 或 JavaScript 文件或項(xiàng)目,小編的解決辦法,希望可以幫助到大家2018-04-04
C#之Windows自帶打印功能的實(shí)現(xiàn)
這篇文章主要介紹了C#之Windows自帶打印功能的實(shí)現(xiàn)方式,具有很好的價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-06-06
C#使用Shader實(shí)現(xiàn)夜幕降臨倒計(jì)時(shí)的效果
這篇文章主要介紹了C#使用Shader實(shí)現(xiàn)夜幕降臨倒計(jì)時(shí)的效果,非常不錯(cuò)具有參考借鑒價(jià)值,需要的朋友可以參考下2016-10-10
C#實(shí)現(xiàn)基于任務(wù)的異步編程模式
本文詳細(xì)講解了C#實(shí)現(xiàn)基于任務(wù)的異步編程模式,文中通過(guò)示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-04-04
解決C# winForm自定義鼠標(biāo)樣式的兩種實(shí)現(xiàn)方法詳解
本篇文章是對(duì)在C#中winForm自定義鼠標(biāo)樣式的兩種實(shí)現(xiàn)方法進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-05-05
Unity幸運(yùn)轉(zhuǎn)盤(pán)實(shí)戰(zhàn)項(xiàng)目
這篇文章主要為大家詳細(xì)介紹了Unity幸運(yùn)轉(zhuǎn)盤(pán)實(shí)戰(zhàn)項(xiàng)目,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-04-04

