InitialDirectory not working

本文关键字:working not InitialDirectory | 更新日期: 2023-09-27 18:03:46

非常非常新的C Sharp,因为它不是我的学习路径的一部分,但我必须在C Sharp编辑小代码,以便我的应用程序工作。我正在使用Ogama,这是一个开源的凝视追踪器,我的项目需要它。更具体地说,是热图。现在,我想将热图保存到一个定向文件夹,并设法找到代码。初始代码是

 public static bool ExportImageToFile(Image image)
{
  SaveFileDialog dlg = new SaveFileDialog();
  dlg.Title = "Please enter filename for image...";
  dlg.InitialDirectory = Environment.SpecialFolder.MyDocuments.ToString();

所以我想我可以改变它,通过遵循其他在线教程,这是我的代码。

public static bool ExportImageToFile(Image image)
{
  SaveFileDialog dlg = new SaveFileDialog();
  dlg.Title = "Please enter filename for image...";
dlg.InitialDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "heatmapimages");

但是它不起作用。当我点击保存文件按钮时,它会将我带到Ogama项目所在的位置。"heatmapimages"文件夹在我的桌面。任何建议吗?提前谢谢你。编辑:设法使它工作,通过改变特殊。Personal to Special.DesktopDirectory。有办法让它自动保存图像吗?这样我就不需要点击保存了?

InitialDirectory not working

"RestoreDirectory"为"true","InitialDirectory"为"SpecialFolder.Desktop"。以下是所有的SpecialFolders供您参考。

如果用户在搜索文件时更改了目录,则将当前目录恢复到原来的值