实现效果:

  使用OpenFileDialog组件打开多个文

知识运用:

  OpenFileDialog组件的Multiselect属性  //是否允许多选

  public bool Multiselect {get;ser;}

  FileNames属性    //获取所有选定的文件的文件名

   public string[] FileName {get;}

实现代码:

        private void button1_Click(object sender, EventArgs e)
        {
            openFileDialog1.Filter = "txt文件(*.txt)|*.txt";
            openFileDialog1.Multiselect = true;
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                string Content = string.Empty;
                foreach(string s in openFileDialog1.FileNames)        //注意是s
                {
                    StreamReader sr = new StreamReader(s,Encoding.Default);
                    Content += sr.ReadToEnd();
                    sr.Close();
                }
                textBox1.Text = Content;
            }
        }

 

相关文章:

  • 2022-12-23
  • 2021-05-29
  • 2021-11-28
  • 2021-10-13
  • 2022-02-15
  • 2022-02-02
  • 2022-01-06
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-07-03
  • 2022-12-23
  • 2022-12-23
  • 2022-02-02
相关资源
相似解决方案