我有一个包含表单的C#库,我在其中使用Folder Browser Dialog Component来获取文件夹路径。 在使用Custom Installer安装我的应用程序期间显示表单。 单击“浏览”按钮以显示文件夹浏览器对话框。对话框打开但没有文件夹列表,空白对话框显示确定和取消按钮。我使用以下代码:
FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog();
folderBrowserDialog.RootFolder = Environment.SpecialFolder.MyComputer;
if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
{
txtDBPath.Text = folderBrowserDialog.SelectedPath;
btnSelectFile.Enabled = true;
}
我该如何解决这个问题。感谢
答案 0 :(得分:0)
我解决了这个问题。
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