按下取消按钮后如何关闭FolderBrowserDialog?

编程入门 行业动态 更新时间:2024-10-27 18:31:04
本文介绍了按下取消按钮后如何关闭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?

本文发布于:2023-11-06 04:39:42,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1562730.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:按下   按钮   FolderBrowserDialog

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!