zoukankan      html  css  js  c++  java
  • C# 基础

    using System.Windows.Forms;
    
    ...
    
    /// <summary>  
    /// 选择保存文件的名称以及路径  取消返回 空"";  
    /// </summary>  
    /// <param name="fileName"></param>  
    /// <param name="filter"></param>  
    /// <param name="title"></param>  
    /// <returns></returns>  
    public static string GetSaveFilePath(string fileName = null, string filter = null, string title = null)
    {
        string path = "";
        SaveFileDialog savedialog = new SaveFileDialog();
        savedialog.AddExtension = true;
        if (string.IsNullOrEmpty(fileName)) savedialog.FileName = DateTime.Now.ToString("yyyyMMdd"); else savedialog.FileName = fileName;
        if (string.IsNullOrEmpty(filter)) savedialog.Filter = "All File|*.*"; else savedialog.Filter = filter;
        if (string.IsNullOrEmpty(title)) savedialog.Title = "保存为"; else savedialog.Title = title;
    
        if (savedialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
        {
        	path = savedialog.FileName;
        }
        return path;
    }
    
    /// <summary>
    /// 选择一个文件
    /// </summary>
    /// <param name="filter">文件类型筛选器</param>
    /// <returns>选择文件完整路径,null没有选择</returns>
    public static string SelectFiles(string filter)
    {
        string[] paths = null;
        string[] names = null;
        // 弹出文件选择框
        if (SelectFiles(filter,false,out paths,out names))
        {
        	return paths[0];
        }
        else
        {
        	return null;
        }
    }
    
    /// <summary>
    /// 选择多个文件
    /// </summary>
    /// <param name="filter">文件类型筛选器</param>
    /// <param name="multiselect">是否可以选择多个文件</param>
    /// <param name="fullpaths">文件完整路径数组</param>
    /// <param name="names">文件名数组</param>
    /// <returns>是否选择成功</returns>
    public static bool SelectFiles(string filter,bool multiselect,out string[] fullpaths,out string[] names)
    {
        // 初始化
        bool result = false;
        fullpaths = null;
        names = null;
    
        OpenFileDialog selectdialog = new OpenFileDialog();
        selectdialog.Multiselect = multiselect;
        if (string.IsNullOrEmpty(filter)) selectdialog.Filter = "All File|*.*"; else selectdialog.Filter = filter;
        // 弹出文件选择框
        result = selectdialog.ShowDialog()== System.Windows.Forms.DialogResult.OK)
        if(result)
        {
        	fullpaths = selectdialog.FileNames;
        	names = selectdialog.SafeFileNames;
        }
        return result;
    }
    
  • 相关阅读:
    OpenCV 学习笔记(1-1)opecv3.41及其扩展库在VS2015下配置
    OpenCV 学习笔记(11)像素级别指针操作
    (19) 树莓派发送微信消息
    mybatis+spring配置
    spring Ioc 实践
    运用BufferedWriter把数据写入文件
    【转】跟我一起学Spring 3(4)–深入理解IoC(控制反转)和DI(依赖注入)
    [转]Spring MVC之@RequestMapping 详解
    python错误处理
    python函数
  • 原文地址:https://www.cnblogs.com/MichaelLoveSna/p/14475241.html
Copyright © 2011-2022 走看看