实现效果:
知识运用:
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; } }