1.添加OpenFileDialog控件
2.选择文件(textbox内容是文件名称)
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog dialog = new OpenFileDialog();
dialog.Filter = "所有文件 (*.*)|(*.*)";
dialog.Title = "打开";
if (dialog.ShowDialog() == DialogResult.OK)
{
string foldPath = dialog.SafeFileName;
textBox1.Text = foldPath;
}
}
3.选择文件夹(textbox内容是文件路径)
private void button2_Click(object sender, EventArgs e)
{
FolderBrowserDialog dialog = new FolderBrowserDialog();
dialog.Description = "选择文件路径";
if (dialog.ShowDialog() == DialogResult.OK)
{
string foldPath = dialog.SelectedPath;
textBox2.Text = foldPath;
}
}
4.textbox文本内容文件的是文件名,文件夹的路径