我希望能够在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中
发布评论