选择 .dll 文件并按 OK 后,浏览对话框将关闭并重新打开。在它再次打开并按 OK 后,它会毫无问题地取值。
这是我的代码
private void btnBrowse_Click(object sender, EventArgs e) {
OpenFileDialog dllDialog = new OpenFileDialog();
dllDialog.Filter = "DLL Files|*.dll";
dllDialog.InitialDirectory = @"C:\";
dllDialog.Title = "Please select .dll file.";
if (dllDialog.ShowDialog() == DialogResult.OK) {
dllDialog.ShowDialog();
tbRepTempLibrary.Text = dllDialog.FileName;
} else {
MessageBox.Show("error");
}
}
最佳答案
您正在调用ShowDialog()
两次。你应该删除第二个,
private void btnBrowse_Click(object sender, EventArgs e)
{
OpenFileDialog dllDialog = new OpenFileDialog();
dllDialog.Filter = "DLL Files|*.dll";
dllDialog.InitialDirectory = @"C:\";
dllDialog.Title = "Please select .dll file.";
if (dllDialog.ShowDialog() == DialogResult.OK)
{
tbRepTempLibrary.Text = dllDialog.FileName;
} else
{
MessageBox.Show("error");
}
}
关于c# - 'OpenFileDialog' 第一次不取值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15944686/