Cas*_*ens 4 c# openfiledialog winforms
文件对话框必须打开关闭之前使用的最后一个目录位置,但我不知道如何执行此操作.我的同事只给我看了一个单词的例子,当你单击"文件"它显示最后使用的文件时,他告诉我使用寄存器或INI文件,这是我以前从未使用过的.
这是我正在使用的代码:
string f_sOudeLocatie = @"D:\path\is\classified";
private void btBrowse_Click(object sender, EventArgs e)
{
OpenFileDialog fdlg = new OpenFileDialog();
fdlg.Title = "Zoek de CSV file";
fdlg.InitialDirectory = f_sOudeLocatie;
fdlg.Filter = "All files (*.*)|*.*|All files (*.*)|*.*";
fdlg.FilterIndex = 1;
fdlg.RestoreDirectory = true;
if (fdlg.ShowDialog() == DialogResult.OK)
{
tbGekozenBestand.Text = fdlg.FileName;
tbVeranderNaamIn.Text = Path.GetDirectoryName(fdlg.FileName);
f_sOudeLocatie = Path.GetDirectoryName(fdlg.FileName);
f_sSourceFileName = fdlg.FileName;
f_sDestFileName = Path.GetFileName(Path.GetDirectoryName(fdlg.FileName)) + ".csv";
btOpslaan.Enabled = true;
tbVeranderNaamIn.ReadOnly = false;
}
}
Run Code Online (Sandbox Code Playgroud)
No *_*ame 10
如果你OpenFileDialog在按钮点击事件之外创建它,它应该记住你去过的最后一个文件夹
string f_sOudeLocatie = @"D:\path\is\classified";
OpenFileDialog fdlg = new OpenFileDialog();
public Form1()
{
InitializeComponent();
fdlg.Title = "Zoek de CSV file";
fdlg.InitialDirectory = f_sOudeLocatie;
fdlg.Filter = "All files (*.*)|*.*|All files (*.*)|*.*";
fdlg.FilterIndex = 1;
fdlg.RestoreDirectory = true;
}
private void btBrowse_Click(object sender, EventArgs e)
{
if (fdlg.ShowDialog() == DialogResult.OK)
{
fdlg.InitialDirectory = fdlg.FileName.Remove(fdlg.FileName.LastIndexOf("\\"));// THIS LINE IS IMPORTENT
tbGekozenBestand.Text = fdlg.FileName;
tbVeranderNaamIn.Text = Path.GetDirectoryName(fdlg.FileName);
f_sOudeLocatie = Path.GetDirectoryName(fdlg.FileName);
f_sSourceFileName = fdlg.FileName;
f_sDestFileName = Path.GetFileName( Path.GetDirectoryName(fdlg.FileName) ) + ".csv";
btOpslaan.Enabled = true;
tbVeranderNaamIn.ReadOnly = false;
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
25697 次 |
| 最近记录: |