/// <summary>
/// 选择文件对话框
/// </summary>
/// <param name="filter">"图像(*.jpg;*.png;*.gif;*.bmp)|*.jpg;*.png;*.gif;*.bmp"</param>
/// <param name="useLastPath"></param>
/// <param name="title"></param>
/// <returns></returns>
public string selectFile(string filter = "", bool useLastPath = true, string title = "选择文件")
{
string FilePath = string.Empty;
OpenFileDialog fileDialog = new OpenFileDialog();//打开文件对话框
string Filter = string.IsNullOrEmpty(filter) ? "所有文件(*.*)|*.*" : filter;
fileDialog.Filter = Filter;//过滤选项设置,文本文件,所有文件。
fileDialog.FilterIndex = 0;//当前使用第二个过滤字符串
fileDialog.RestoreDirectory = true;//对话框关闭时恢复原目录
fileDialog.Title = title;
if (fileDialog.ShowDialog() == DialogResult.OK)
{
FilePath = fileDialog.FileName;
if (useLastPath)
{
System.IO.Path.GetDirectoryName(FilePath);//更改默认路径为最近打开路径
}
}
return FilePath;
}