c# 用openfiledialog打开一个txt文件并显示在richtextbox中,谢谢!!

如题所述

第1个回答  2011-09-09
你这样做:
1.应用命名空间:using System.IO
2.在按钮button1中的点击事件中添加如此代码:
this.openFileDialog1.ShowDialog();
string filePath = this.openFileDialog1.FileName;
StreamReader sReader = new StreamReader(filePath, Encoding.Default);
this.richTextBox1.Text = sReader.ReadToEnd();
sReader.Dispose();

这样应该就可以了。本回答被提问者采纳
第2个回答  2011-09-09
rtbeditor.LoadFile(openFileDialog1.FileName, RichTextBoxStreamType.PlainText);
rtbeditor 为richtextbox的NAME
第3个回答  2011-09-09
MSDN上输入open……有实例
相似回答