none
打开"对话框"后,在"文件名"后始终出现的是OpenFileDialog RRS feed

  • 问题

  • 我想使文件名后面不出现"OpenFileDialog",待选择文件后才会出现文件名.我试了5个自编的程序都有这种现象.用xp自带的"记事本"或"写字板"打开对话框后文件名后不会出现"OpenFileDialig".请指点这是怎么回事.

     private void 打开OToolStripMenuItem_Click(object sender, EventArgs e)
            {
                openFileDialog1.Filter = "文本文件(*.*)|*.txt|所有文件(*.*)|*.*";//设置文件类型
                openFileDialog1.FilterIndex = 1;                                 //设置默认文件类型的显示顺序
                openFileDialog1.RestoreDirectory = true;                         //打开对话框是否记忆上次打开的目录
                StreamReader sr = null;                                           //定义StreamReader对象
                if (openFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    try
                    {
                        openfilepath = openFileDialog1.FileName;                  //获取打开的文件路径
                        string name = openfilepath.Substring(openfilepath.LastIndexOf("\\") + 1);
                        this.Text = name;                                         //文件名作为标题
                        sr = new StreamReader(openfilepath, Encoding.Default);     //实例化sr
                        richTextBox1.Text = sr.ReadToEnd();
                       // richTextBox2.Text = richTextBox1.Text;           //读取的文件放在右边框
                    }
                    catch
                    {
                        MessageBox.Show("打开文件出错.", "错误", System.Windows.Forms.MessageBoxButtons.OK,
                           System.Windows.Forms.MessageBoxIcon.Warning);
                        return;

                    }
                    finally
                    {
                        if (sr != null)
                        {
                            sr.Close();//关闭对象sr
                            sr.Dispose();//释放对象sr资源
                        }
                    }
                }

    2011年3月9日 12:04

答案

全部回复