110,568
社区成员
发帖
与我相关
我的任务
分享
public partial class Form1 : Form
{
string defaultfilePath = "";
private void button1_Click(object sender, EventArgs e)
{
FolderBrowserDialog dialog = new FolderBrowserDialog();
//首次defaultfilePath为空,按FolderBrowserDialog默认设置(即桌面)选择
if (defaultfilePath != "")
{
//设置此次默认目录为上一次选中目录
dialog.SelectedPath = defaultfilePath;
}
if (dialog.ShowDialog() == DialogResult.OK)
{
//记录选中的目录
defaultfilePath = dialog.SelectedPath;
}
}
}