c#怎么选择多个文件代码实现
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace selectFiles
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog dlg = new OpenFileDialog();
dlg.Multiselect = true;
dlg.DefaultExt = ".txt";
dlg.Filter = "记事本文件|*.txt";
if (dlg.ShowDialog() == DialogResult.OK)
{
var sb = new StringBuilder();
foreach (string file in dlg.FileNames) {
sb.Append(file);
sb.Append("\r\n");
}
textBox1.Text = sb.ToString();
}
}
}
}