在下面的代码中,我将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;
}
}发布于 2012-02-15 23:11:42
来自RestoreDirectory的MSDN文档
获取或设置一个值,该值指示对话框在关闭之前是否还原当前目录。
所以这个属性是关于还原OS当前目录的。
但是您在代码中也使用了InitialDirectory属性,每次强制对话框从@"c:\";路径启动。删除它,它将解决您的问题。
https://stackoverflow.com/questions/9295739
复制相似问题