在C#中将.txt文件打开到richTextBox中

编程入门 行业动态 更新时间:2024-10-09 20:27:50
本文介绍了在C#中将.txt文件打开到richTextBox中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我希望能够在c#中将.txt文件打开成一个richtextbox,并且将其打开成为我称为'笔记'的全局变量,但不知道如何执行此操作。这是我目前的代码:

OpenFileDialog opentext = new OpenFileDialog(); if(opentext.ShowDialog()== DialogResult.OK) { richTextBox1.Text = opentext.FileName; Globals.notes = opentext.FileName; }

唯一的问题是它不会出现在richtextbox或全局中varibale和全局允许它以另一种形式在另一个richtextbox中查看。所以请你能帮忙,理想的情况是将.txt文件放入这两个文件中,

谢谢

解决方案

richTextBox1.Text =文件名.ReadAllText(opentext.FileName); Globals.notes = richTextBox1.Text;

您可能还想更正此问题:

if(opentext.ShowDialog()== DialogResult.OK)

I want to be able to open a .txt file up into a richtextbox in c# and also into a global variable i have made called 'notes' but don't know how to do this. This is the code i have at the moment:

OpenFileDialog opentext = new OpenFileDialog(); if (opentext.ShowDialog() == DialogResult.OK) { richTextBox1.Text = opentext.FileName; Globals.notes = opentext.FileName; }

Only problem is it doesn't appear in neither the richtextbox nor in the global varibale, and the global allows it to be viewed in another richtextbox in another form. So please can you help, with ideally the .txt file going into both,

Thanks

解决方案

Do you mean you want to have the text displayed or the filename?

richTextBox1.Text = File.ReadAllText(opentext.FileName); Globals.notes = richTextBox1.Text;

You probably also want to correct this to:

if (opentext.ShowDialog() == DialogResult.OK)

更多推荐

在C#中将.txt文件打开到richTextBox中

本文发布于:2023-06-10 18:39:56,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:开到   中将   文件   richTextBox   txt

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!