“.RestoreDirectory”不起作用
在下面的代码中,我将 ofd1.RestoreDirectory
设置为 false
但是,该对话框每次都会打开初始目录。难道有什么我不知道的事情吗?
private void btnMeshFile_Click(object sender, EventArgs e)
{
OpenFileDialog ofd1 = new OpenFileDialog();
ofd1.Title = "Open";
ofd1.InitialDirectory = @"c:\";
ofd1.Filter = "All files (*.*)|*.*|All files (*.*)|*.*";
ofd1.FilterIndex = 2;
ofd1.RestoreDirectory = false;
if (ofd1.ShowDialog() == DialogResult.OK)
{
string fileName = Path.GetFileName(ofd1.FileName);
MeshDirectoryPath = Path.GetFullPath(ofd1.FileName).Replace(@"\", @"\\");
txtMeshFile.Text = fileName;
}
}
In the following code I set ofd1.RestoreDirectory
as false
however, the dialog opens the inital directory everytime. Is there something that I am not aware of?
private void btnMeshFile_Click(object sender, EventArgs e)
{
OpenFileDialog ofd1 = new OpenFileDialog();
ofd1.Title = "Open";
ofd1.InitialDirectory = @"c:\";
ofd1.Filter = "All files (*.*)|*.*|All files (*.*)|*.*";
ofd1.FilterIndex = 2;
ofd1.RestoreDirectory = false;
if (ofd1.ShowDialog() == DialogResult.OK)
{
string fileName = Path.GetFileName(ofd1.FileName);
MeshDirectoryPath = Path.GetFullPath(ofd1.FileName).Replace(@"\", @"\\");
txtMeshFile.Text = fileName;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
来自
RestoreDirectory
的 MSDN 文档所以这个属性是关于恢复
OS
当前目录的。但是您在代码中还使用
InitialDirectory
属性,强制对话框每次都从@"c:\";
路径启动。删除它,它将解决您的问题。From MSDN documentation of
RestoreDirectory
So this property is about restoring
OS
current directory.But you, in the code also use
InitialDirectory
property, forcing the dialog every time start from@"c:\";
path. Remove this, and it will resolve your problem.