如题,谢谢

解决方案 »

  1.   

    if (openFileDialog1.ShowDialog() == DialogResult.OK)
    {
        listbox.Items.Add(openFileDialog1.FileName);
    }
      

  2.   

    晕,没看清题目。你是显示文件名,还是显示内容?
    显示内容:if (openFileDialog1.ShowDialog() == DialogResult.OK)
    {
        StreamReader reader = new StreamReader(openFileDialog1.FileName);
        string line = reader.ReadLine();
        while (line != null)
        {
            listbox.Items.Add(line);
            line = reader.ReadLine();        
        }
        reader.Close();
    }
      

  3.   

    谢谢啦!那怎样才能将内容直接显示出来呢?比如:打开一个文档格式的,直接将文档打开显示其内容;打开一个doc格式的,word直接打开显示内容。
      

  4.   

    搂主4楼疑问可以这样做:Process.Start(文档全路径);
      

  5.   

    private void button1_Click(object sender, EventArgs e)
            {
                OpenFileDialog openFiledDialog=new OpenFileDialog();
                openFiledDialog.InitialDirectory = "D:\\";
                openFiledDialog.Filter = "文本文件|*.*|C#文件|*.cs|所有文件|*.*";
                openFiledDialog.FilterIndex= 1;
                if (openFiledDialog.ShowDialog() == DialogResult.OK)
                { 
                //打开文件对话框中选择的文件名
                    string fname = openFiledDialog.FileName;
                    //创建从字符串进行读取的StringReader对象
                    StreamReader sr = File.OpenText(fname);
                    string str;
                    while((str=sr.ReadLine())!=null)
                    {
                    //将读出的字符串在richTextBox1中显示;
                        this.richTextBox1.Text+=str;
                    }
      

  6.   

    怎样才能将选中的图片显示在listBox中!!没有看明白。