zoukankan      html  css  js  c++  java
  • Winform窗体程序 按钮选择文件及存储位置

    winform窗体文件中时常需要选择文件及文件存储位置

    选择文件

       System.Windows.Forms.OpenFileDialog fd = new OpenFileDialog();
                fd.Title = "选择文件";//选择框名称        
                fd.Filter = "xls files (*.xlsx)|*.xlsx";//选择文件的类型为Xls表格          
                if (fd.ShowDialog() == DialogResult.OK)//当点击确定               
                {
    
                    SelectFilePath.Text = fd.FileName.Trim();  //文件路径
                                                               //     SelectFilePath.Text = SelectFilePath.Text.Replace("\", "/");
    
                }
    选择文件

    选择多个文件:

      OpenFileDialog dlg = new OpenFileDialog();
                dlg.Multiselect = true;//等于true表示可以选择多个文件
                                       //dlg.DefaultExt = ".txt";
                                       //dlg.Filter = "记事本文件|*.txt";
                dlg.ShowDialog();
                filepath.Text = "已选择" + dlg.FileNames.Length + "个文件";
                str = dlg.FileNames;
    选择多个文件

    选择文件夹

       FolderBrowserDialog ofd = new FolderBrowserDialog();
                ofd.ShowDialog();
                DownloadPath.Text = ofd.SelectedPath.ToString();
    选择文件存储位置
  • 相关阅读:
    BZOJ1443 [JSOI2009]游戏Game
    BZOJ4950 [Wf2017]Mission Improbable
    假期编程
    假期编程
    假期编程
    假期编程
    假期编程练习-求和
    假期编程练习——一个数的n次幂取余
    假期编程练习———十进制转二进制
    小球抛物线运动
  • 原文地址:https://www.cnblogs.com/my2020/p/14343683.html
Copyright © 2011-2022 走看看