设置 SaveFileDialog 的初始目录? [英] Setting the initial directory of an SaveFileDialog?

查看:20
本文介绍了设置 SaveFileDialog 的初始目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要一个具有以下行为的 SaveFileDialog:

I'd like a SaveFileDialog with the following behavior:

  • 第一次打开它时,它会转到我的文档".

  • The first time you open it, it goes to "My Documents".

之后,它会转到最后选择的文件夹.实现此目标的最佳方法是什么?

Afterwards, it goes to the last selected folder. What's the best way to accomplish this?

如果我不设置 InitialDirectory,它会进入 exe 的目录 - 这不是我想要的.它会记住上次选择的目录 - 即使在执行之间也是如此.

If I don't set the InitialDirectory, it goes to the exe's directory - which is not what I want. It rememebers the last selected directory though - even between executions.

如果我设置了 InitialDirectory,它不会记住上次选择的目录.当然,我可以将上次选择的目录保存在注册表中 :( 但我正在寻找更好的解决方案.

If I set the InitialDirectory, it does not remember the last selected directory. Of course, I could save the last selected directory in the registry :( but I am looking for a better solution.

      SaveFileDialog dialog = new SaveFileDialog();
      //??? dialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
      dialog.ShowDialog();

有什么建议吗?

推荐答案

您需要设置RestoreDirectorytrue 以及 InitialDirectory 属性.

You need to set the RestoreDirectory to true as well as the InitialDirectory property.

这篇关于设置 SaveFileDialog 的初始目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆