winform选择文件夹

using System;using System.Windows.Forms;namespace WindowsFormsApp1{    public partial class Form1 : Form    {        public Form1()        {            InitializeComponent();        }        /// <summary>        /// 好用一点的打开目录        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void button1_Click(object sender, EventArgs e)        {            OpenFileDialog ofd = new OpenFileDialog();            ofd.DefaultExt = "xls";            ofd.FileName = "默认名字";            ofd.Filter = "Excel Document(*.xls)|*.xls";            //如果设置了默认路径,那下次打开依然是这个默认路径,            //不应该和RestoreDirectory =true同时使用。            //sfd.InitialDirectory = "C:\\";            //保存路径,每次打开,都选择上次的目录,            ofd.RestoreDirectory = true;             if (ofd.ShowDialog() != System.Windows.Forms.DialogResult.OK)            {                return;            }        }        /// <summary>        /// 难用的打开目录        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void button2_Click(object sender, EventArgs e)        {            FolderBrowserDialog fbd = new FolderBrowserDialog();            //即使设置了这个默认路径,但滚动条不会自动滚动到那儿            fbd.SelectedPath = "D:\\app";            if(fbd.ShowDialog()!=DialogResult.OK)            {                return;            }        }    }}

第一种:

第二种:

(0)

相关推荐