FolderBrowserDialog在取消时再次打开

时间:2014-07-04 16:28:19

标签: vb.net folderbrowserdialog

当我打开FolderBrowserDialog然后单击取消它再次重新打开。 但是,在再次单击取消时,在第二个FolderBrowserDialog上,它会正确关闭。 当您在第二个FolderBrowserDialog上选择路径时,它会执行或不返回任何内容 当我点击第一个取消时,我可以停止出现第二个FolderBrowserDialog吗? 我不知道为什么会出现。提前谢谢。

这是我的代码:

Dim apppath
Try
    FolderBrowserDialog1.RootFolder = Environment.SpecialFolder.Desktop
    FolderBrowserDialog1.SelectedPath = "C:\"
    FolderBrowserDialog1.Description = "Select File Location Path"
    If FolderBrowserDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
        apppath = FolderBrowserDialog1.SelectedPath
    ElseIf FolderBrowserDialog1.ShowDialog() = Windows.Forms.DialogResult.Cancel    Then
        Exit Sub
    End If
    My.Computer.FileSystem.WriteAllText(apppath & "apppath.txt", apppath, False)
    MessageBox.Show(apppath)
Catch ex As Exception
    MessageBox.Show("Invalid Location")
    Exit Sub

结束尝试

1 个答案:

答案 0 :(得分:1)

尝试这样的事情

Dim result as Windows.Forms.DialogResult = FolderBrowserDialog1.ShowDialog()
If result = Windows.Forms.DialogResult.OK Then
    apppath = FolderBrowserDialog1.SelectedPath
ElseIf result = Windows.Forms.DialogResult.Cancel    Then
    Exit Sub
End If