当前位置:网站首页>C WinForm development opens the txt file and displays it in RichTextBox. Add the function of saving after editing
C WinForm development opens the txt file and displays it in RichTextBox. Add the function of saving after editing
2022-07-22 21:43:00 【A chicken with multiple senses】
Add one openFileDialog Components , Then write the corresponding function : Here is a pre-defined RichTextBox rtbInfo;
private void OpenFromFile()
{
openFileDialog.Filter = "txt Format (*.txt)|*.txt| All the files |*.*";
openFileDialog.Title = " open ";
openFileDialog.FileName = pname;// The path of the file to open
rtbInfo.Clear();// First clear Show new content again
rtbInfo.LoadFile(openFileDialog.FileName, RichTextBoxStreamType.PlainText); // open
rtbInfo.Show();// Show
}
This will open and display txt file .
Here is how to save by clicking :
private void SaveToFile()
{
//saveFileDialog.InitialDirectory = pname;// Set the default directory for saving
saveFileDialog.FileName = pname;
saveFileDialog.Filter = "txt files(*.txt)|*.txt|all files(*.*)|*.*";
saveFileDialog.FilterIndex = 1;// The default display save type is TXT
saveFileDialog.RestoreDirectory = true;
rtbInfo.SaveFile(saveFileDialog.FileName, RichTextBoxStreamType.PlainText);
}
Directly use a click event to call the function to save the event .
边栏推荐
猜你喜欢
重新安装的nvidia显卡驱动
英语四六级听力有线传输无线发射系统方案
Web编程入门 3.1 选择框select
9. User authority related commands
C# Winform开发 弹出式输入框 文本框
相比技术与产品 倾听与意见才是Web3当下的首要任务
WinAppDriver 自动测试 winform 自动测试的部署
Sensoro Fu Liu Wei: innovative technology services build a digital base for grass-roots governments
7-1 detailed steps of installing SSH on virtual machine
[PROBLEMS] solve unable to connect to redis; nested exception is io.lettuce.core.RedisConnectionException
随机推荐
Process control
Cjson source code reading notes
云报传媒广场数字电视转模拟系统设计分享
Servlet
小区IP网络广播背景系统解决方案-基于局域网、专网或广域网传输
校园IPTV数字电视教学直播系统在淮安生态文旅区实验小学的应用
扫雷小游戏(C语言实现)
【问题篇】解决Unable to connect to Redis; nested exception is io.lettuce.core.RedisConnectionException
编译gdb7.11.1报错解决
Compared with technology and products, listening and opinions are the top priority of Web3 at present
NVIDIA Clara data
已经两点经纬度,计算两点之间距离
6.echo 和重定向
Binance Chinese community x cartesi AMA review
10. System information related commands
Cartesi 2022 年 3 月回顾
Bash basic function - input / output redirection
7-1虚拟机上安装SSH的详细步骤
NVIDIA CLARA资料
FPN data