gpt4 book ai didi

c# - 'OpenFileDialog' 第一次不取值

转载 作者:太空宇宙 更新时间:2023-11-03 18:10:42 24 4
gpt4 key购买 nike

选择 .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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com