InPowerS.Net

 找回密碼
 註冊
搜索
查看: 1794|回復: 0

[轉貼]VB.Net2005裡實現檔帶更新進度條下載

[複製鏈接]
發表於 2008-12-25 02:41:00 | 顯示全部樓層 |閱讀模式
Public Class Form1
    Private WithEvents myWebclient As Net.WebClient
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim remoteUri As String = "http://www.uz58.com/smartserver.exe"
        Dim fileName As String = "C:\xx.rar"
        myWebclient = New Net.WebClient()
        myWebclient.DownloadFileAsync(New Uri(remoteUri), fileName)
    End Sub
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        myWebclient.CancelAsync()       '中斷下載   
    End Sub
    Private Sub myWebclient_DownloadFileCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.AsyncCompletedEventArgs) Handles myWebclient.DownloadFileCompleted
        MsgBox("下載完畢")
    End Sub
    Private Sub myWebclient_DownloadProgressChanged(ByVal sender As Object, ByVal e As System.Net.DownloadProgressChangedEventArgs) Handles myWebclient.DownloadProgressChanged
        Me.Label1.Text = CStr(e.UserState) & "         downloaded   " & e.BytesReceived & "   of   " & e.TotalBytesToReceive & "   bytes.   " & e.ProgressPercentage & "   %   complete..."
    End Sub
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    End Sub
End Class
您需要登錄後才可以回帖 登錄 | 註冊

本版積分規則

小黑屋|Archiver|手機版|InPowerS.Net

GMT+8, 2018-10-15 17:32

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回復 返回頂部 返回列表