C# WinForm 选择目录
选择文件
private string openFileDialog(string name)
{
string FilePath = name;
OpenFileDialog dialog = new OpenFileDialog();
////是否支持多个文件的打开?
//dialog.Multiselect = false;
////标题
//dialog.Title = "请选择文件";
////文件类型
//dialog.Filter = "图片(*.*)|*.*";//或"图片(*.jpg;*.bmp)|*.jpg;*.bmp"
if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
//获取选择的文件路径
FilePath = dialog.FileName;
}
return FilePath;
}
选择目录
private string FolderDialog(string name)
{
string FolderPath = name;
FolderBrowserDialog dialog = new FolderBrowserDialog();
dialog.Description = "选择目录";
if (dialog.ShowDialog() == DialogResult.OK)
{
//获取选择的目录路径
FolderPath = dialog.SelectedPath;
}
return FolderPath;
}