很明显,错误提示你,你类文件的顶上,有个 using System.Windows.Forms.CommonDialog; 语句,有问题 因为 System.Windows.Forms.CommonDialog 这个是一个类,不是命令空间,改一下就好了把 using System.Windows.Forms.CommonDialog; 这一句删除了,如果没有 using System.Windows.Forms; 这个语句,则, 删除 using System.Windows.Forms.CommonDialog; 再加一句 using System.Windows.Forms;
我改掉了但是出来了下面的提示: 找不到类型或命名空间名称“Stream”(是否缺少 using 指令或程序集引用?) 名称“myStream”在类或命名空间“WindowsApplication1.Form8”中不存在 找不到类型或命名空间名称“mystream”(是否缺少 using 指令或程序集引用?怎么办啊~~~~~~~~·····
using System.Windows.Forms.CommonDialog; 把这个后面CommonDialog删掉即可
找不到类型或命名空间名称“Stream”(是否缺少 using 指令或程序集引用?)
名称“myStream”在类或命名空间“WindowsApplication1.Form8”中不存在
找不到类型或命名空间名称“mystream”(是否缺少 using 指令或程序集引用?怎么办啊~~~~~~~~·····
richTextBox.Text = sr.ReadToEnd();
private void menuItem7_Click_1(object sender, System.EventArgs e)
{
Stream myStream;
OpenFileDialog openFileDialog1=new OpenFileDialog ();
openFileDialog1.InitialDirectory="c:\\";
openFileDialog1.Filter="All files (*.*)|*.*|文本文件 (*.txt)|*.txt";
openFileDialog1.FilterIndex=2;
openFileDialog1.RestoreDirectory=true;
if(openFileDialog1.ShowDialog() == DialogResult.OK)
{
if((myStream=openFileDialog1.OpenFile())!=null)
{
myStream.Close();
}
}
string path = this.richTextBox1.Text;
StreamReader sr = new StreamReader(path);
richTextBox1.Text = sr.ReadToEnd();
}
程序有什么错误呢?运行可以就是最后出来一个貌似中断的信息。多有叨扰,还请原谅
using (OpenFileDialog dlgText = new OpenFileDialog())
{
dlgText.Filter = @"(*.txt)|*.txt";
if (dlgText.ShowDialog() == DialogResult.OK)
{
if (File.Exists(dlgText.FileName))
{
label1.Text = "数据文件已加载";
this.datafile = dlgText.FileName;
this.data = true;
}
}
}
其他信息:空路径名是非法的
StreamReader sr = new StreamReader(path); richTextBox1.Text为空,StreamReader sr = new StreamReader(path); 会出错