1

我有一个 C# 库,其中包含我使用文件夹浏览器对话框组件来获取文件夹路径的表单。在使用自定义安装程序安装我的应用程序期间显示表单。单击浏览按钮以显示文件夹浏览器对话框时。对话框打开但没有文件夹列表,显示空白对话框,带有确定和取消按钮。我正在使用以下代码:

FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog();
folderBrowserDialog.RootFolder = Environment.SpecialFolder.MyComputer;
if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
{
    txtDBPath.Text = folderBrowserDialog.SelectedPath; 
    btnSelectFile.Enabled = true;
}

我该如何解决这个问题。谢谢

4

1 回答 1

1

我解决了这个问题。

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
于 2015-03-26T15:27:08.757 回答