大漠孤烟

导航

统计

选择文件对话框

/// <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;
}

posted on   jnmcok  阅读(18)  评论(0编辑  收藏  举报

(评论功能已被禁用)
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· .NET Core 中如何实现缓存的预热?
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 如何调用 DeepSeek 的自然语言处理 API 接口并集成到在线客服系统
点击右上角即可分享
微信分享提示