zoukankan      html  css  js  c++  java
  • Winform中使用打开文件对话框和文件夹浏览对话框

    在进行winform开发的时候经常会使用打开文件对话框(OpenFileDialog)和文件夹浏览对话框(FolderBrowserDialog)。

    一、文件夹浏览对话框(FolderBrowserDialog)

    第一步、从工具箱中引入一个FolderBrowserDialog组件,当这个组件被添加到窗体上时会出现在窗体下方的空白区域,如图:

    第二步、需要一个按钮激发打开文件夹的行为,针对这个按钮btnSelectPath我们可是使用如下方法:

    private void btnSelectPath_Click(object sender, EventArgs e)
    
    {
    
        folderBrowserDialog1.Description = "请选择文件夹";
    
        folderBrowserDialog1.ShowNewFolderButton = true;
    
        folderBrowserDialog1.RootFolder = Environment.SpecialFolder.Desktop;
    
        DialogResult result = folderBrowserDialog1.ShowDialog();
    
        if (result == DialogResult.OK)
    
        {
    
            txtMainDir.Text = folderBrowserDialog1.SelectedPath;
    
        }
    
    }

    二、打开文件对话框(OpenFileDialog)

    第一步、同上,需要引入OpenFileDialog组件,如上图所示

    第二步、针对按钮btnSelectFile写代码:

    private void btnSelectFile_Click(object sender, EventArgs e)
    
    {
    
        openFileDialog1.Filter = "Special Files(*.xls)|*.xls|All files (*.*)|*.*";
    
        DialogResult result = openFileDialog1.ShowDialog();
    
        if (result == DialogResult.OK)
    
        {
    
            txtFile.Text = openFileDialog1.FileName;
    
        }
    
    }

    over.

  • 相关阅读:
    Populating Next Right Pointers in Each Node II
    Populating Next Right Pointers in Each Node
    Construct Binary Tree from Preorder and Inorder Traversal
    Construct Binary Tree from Inorder and Postorder Traversal
    Path Sum
    Symmetric Tree
    Solve Tree Problems Recursively
    632. Smallest Range(priority_queue)
    609. Find Duplicate File in System
    poj3159最短路spfa+邻接表
  • 原文地址:https://www.cnblogs.com/fanyong/p/3051908.html
Copyright © 2011-2022 走看看