文件夹浏览器对话框组件在windows窗体中不显示文件夹列表
本文关键字:文件夹 显示 显示文件 列表 windows 浏览器 对话框 组件 窗体 | 更新日期: 2023-09-27 18:19:29
我有一个包含表单的C#库,我在其中使用文件夹浏览器对话框组件来获取文件夹路径。使用自定义安装程序安装我的应用程序时会显示窗体。单击浏览按钮时显示文件夹浏览器对话框。对话框已打开,但没有文件夹列表,空白对话框显示"确定"answers"取消"按钮。我正在使用以下代码:
FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog();
folderBrowserDialog.RootFolder = Environment.SpecialFolder.MyComputer;
if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
{
txtDBPath.Text = folderBrowserDialog.SelectedPath;
btnSelectFile.Enabled = true;
}
我该如何解决这个问题。感谢
我解决了这个问题。
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Try
Dim MyThread As New Threading.Thread(AddressOf ShowMyFolderBrowserDialog)
MyThread.SetApartmentState(Threading.ApartmentState.STA)
MyThread.Start()
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Setup")
End Try
End Sub
Private Sub ShowMyFolderBrowserDialog()
Try
Me.FolderBrowserDialog1.RootFolder = Environment.SpecialFolder.MyComputer
Me.FolderBrowserDialog1.Description = "Select folder"
If System.IO.Directory.Exists(Me.TextBox1.Text) Then
Me.FolderBrowserDialog1.SelectedPath = Me.TextBox1.Text
End If
If Me.FolderBrowserDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
Me.TextBox1.Text = Me.FolderBrowserDialog1.SelectedPath
End If
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Setup")
End Try
End Sub