VB.NET中图片下载完毕后,如何激活下载按钮?

2026-05-06 12:351阅读0评论SEO基础
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计251个文字,预计阅读时间需要2分钟。

VB.NET中图片下载完毕后,如何激活下载按钮?

好的,以下是简化后的内容:

Visual Basic中遇到问题,下载图片代码后,灰色下载按钮。Button1.Enabled=False后,想再次启用。

好吧我在Visual Basic中遇到问题,我得到了下载图片的代码.

WC.DownloadFileAsync(New Uri("picturelinkhere"), "c:\myfile.jpg")

之后,我有一个灰色下载按钮的代码

Button1.Enabled = False

问题是我想在再次启用Button1之前等待文件下载完成.

我试过用

System.Threading.Thread.Sleep(1000)

但问题在于它使得程序中的进度条非常滞后.

有任何想法吗?

VB.NET中图片下载完毕后,如何激活下载按钮?

根据 MSDN:

To receive notification when the file is available, add an event handler to the DownloadFileCompleted event.

所以,例如,你可以这样做:

AddHandler WC.DownloadFileCompleted, AddressOf DownloadFileCompleted

然后在事件处理程序方法中重新启用按钮,如下所示:

Private Sub DownloadFileCompleted(sender As Object, e As AsyncCompletedEventArgs) Button1.Enabled = True End Sub

本文共计251个文字,预计阅读时间需要2分钟。

VB.NET中图片下载完毕后,如何激活下载按钮?

好的,以下是简化后的内容:

Visual Basic中遇到问题,下载图片代码后,灰色下载按钮。Button1.Enabled=False后,想再次启用。

好吧我在Visual Basic中遇到问题,我得到了下载图片的代码.

WC.DownloadFileAsync(New Uri("picturelinkhere"), "c:\myfile.jpg")

之后,我有一个灰色下载按钮的代码

Button1.Enabled = False

问题是我想在再次启用Button1之前等待文件下载完成.

我试过用

System.Threading.Thread.Sleep(1000)

但问题在于它使得程序中的进度条非常滞后.

有任何想法吗?

VB.NET中图片下载完毕后,如何激活下载按钮?

根据 MSDN:

To receive notification when the file is available, add an event handler to the DownloadFileCompleted event.

所以,例如,你可以这样做:

AddHandler WC.DownloadFileCompleted, AddressOf DownloadFileCompleted

然后在事件处理程序方法中重新启用按钮,如下所示:

Private Sub DownloadFileCompleted(sender As Object, e As AsyncCompletedEventArgs) Button1.Enabled = True End Sub