16,549
社区成员
发帖
与我相关
我的任务
分享
'这里是进度条显示
Private Sub ShowDownProgress(ByVal sender As Object, ByVal e As System.Net.DownloadProgressChangedEventArgs)
ProgressBar1.Value = e.ProgressPercentage
End Sub
Dim myWebClient As WebClient
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
myWebClient = New WebClient
AddHandler myWebClient.DownloadProgressChanged, AddressOf ShowDownProgress '这一句是在网上看到的,用这句来捕获下载进度变化事件,不知道对不对。
AddHandler myWebClient.DownloadDataCompleted, AddressOf DownloadDataCompleted
End Sub
Private Sub DownLoadFiles()
myWebClient.DownloadFileAsync(New Uri("http://dlsw.baidu.com/sw-search-sp/soft/3a/12350/QQ_V7.6.15742.0_setup.1441010663.exe"), "QQ_V7.6.15742.0_setup.1441010663.exe")
End Sub
Private Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button2.Click
DownLoadFiles()
End Sub
'这里是进度条显示
Private Sub ShowDownProgress(ByVal sender As Object, ByVal e As System.Net.DownloadProgressChangedEventArgs)
Invoke(New Action(Of Integer)(Sub(i) ProgressBar1.Value = i), e.ProgressPercentage)
End Sub
'这里是完成部分
Sub DownloadDataCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.AsyncCompletedEventArgs)
If MessageBox.Show("您已经下载成功,是否打开应用程序?", "提示", MessageBoxButtons.YesNo) = DialogResult.Yes Then
System.Diagnostics.Process.Start("QQ_V7.6.15742.0_setup.1441010663.exe") ' 启动刚下载的程序
Else
End If
End Sub
#5
不行,比如像下面这样: Private Sub ShowDownProgress(ByVal sender As Object, ByVal e As System.Net.DownloadProgressChangedEventArgs) ProgressBar1.Value = e.BytesReceived Label1.Text = e.BytesReceived.ToString End Sub Label1的Text属性没有发生变化,说明AddHandler myWebClient.DownloadProgressChanged, AddressOf ShowDownProgress 没起作用,具体我也不是很清楚了,新手不懂啊。