- A+
所属分类:.NET技术
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) { SaveFileDialog sfd = new SaveFileDialog(); sfd.DefaultExt = "xls"; sfd.FileName = "默认名字"; sfd.Filter = "Excel Document(*.xls)|*.xls"; //如果设置了默认路径,那下次打开依然是这个默认路径, //不应该和RestoreDirectory =true同时使用。 //sfd.InitialDirectory = "C:\"; //保存路径,每次打开,都选择上次的目录, sfd.RestoreDirectory = true; if (sfd.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; } } } }
第一种:
第二种: