OpenFileDialog中initialDirectory的用法
1个回答
展开全部
在InitialDirectory中可以设置打开对话框的初始路径
C# code
private string Road = null;
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.InitialDirectory = "D:\\";
if (Road != null) { ofd.InitialDirectory = Road ; }
if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
this.Text = ofd.FileName;
Console.WriteLine(ofd.FileName);
Road = ofd.FileName.Substring(0,ofd.FileName.LastIndexOf('\\'));
Console.WriteLine(Road);
}
}
C# code
private string Road = null;
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.InitialDirectory = "D:\\";
if (Road != null) { ofd.InitialDirectory = Road ; }
if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
this.Text = ofd.FileName;
Console.WriteLine(ofd.FileName);
Road = ofd.FileName.Substring(0,ofd.FileName.LastIndexOf('\\'));
Console.WriteLine(Road);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询