本文介绍了按下取消按钮后如何关闭FolderBrowserDialog?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当按下取消按钮时,如何关闭FolderBrowserDialog? 这是我的代码:
How can I close the FolderBrowserDialog when the cancel button is pressed? Here is my code:
Private Sub BackupButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BackupButton.Click With FolderBrowserDialog1 .Description = "Select Backup Location:" .RootFolder = Environment.SpecialFolder.Desktop .SelectedPath = Environment.SpecialFolder.Desktop If .ShowDialog = Windows.Forms.DialogResult.OK Then Try destPath = .SelectedPath Catch ex As Exception End Try ElseIf (.ShowDialog = DialogResult.Cancel) Then Return End If End With sourcePath = Application.StartupPath & "\SavedFiles\" 'If Not Directory.Exists(sourcePath) Then 'MsgBox("Source folder does not exist") 'Return 'End If CopyDir.CopyAll(New DirectoryInfo(sourcePath), New DirectoryInfo(destPath + "\SavedFiles\")) End Sub在上面的代码中,我不知道当按下取消"按钮时,有什么命令可以关闭该对话框.
In the above code, I do not know what command can close that dialog when the cancel button is pressed. Any tips?
推荐答案没关系,花了很多时间调试后,自己修复了它.您所要做的就是从Try语句之间的底部移动CopyDir和sourcePath,并在End Try语句之后删除ElseIf和te Return,它运行良好.问题是它是在按下取消"按钮时显示了两次对话框,或者锁定了对话框.无论哪种方式,它现在都可以工作. :) Never mind, fixed it myself after spending a lot of time debugging. All you had to do was move the CopyDir and sourcePath from the bottom in between the Try statement and delete the ElseIf and te Return after the End Try statement and it worked fine. The problem was it was either showing the dialog twice when the cancel button was pressed, or it was locking up. Either way it is now working. :)
更多推荐
按下取消按钮后如何关闭FolderBrowserDialog?
发布评论