您好,登錄后才能下訂單哦!
今天就跟大家聊聊有關VB.NET下載程序實現代碼怎么編寫,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結了以下內容,希望大家根據這篇文章可以有所收獲。
對于VB.NET語言的應用來說,其中有很多小技巧值得我們去掌握,來充實我們的開發經驗,以提高編程效率。比如VB.NET下載程序的實現,就是其中一個很有用的編程技巧,能幫助我們很好的解決開發中所遇到的相關問題。
VB.NET下載程序代碼示例:
Public Shared fpath As String
Dim fsize As Long
Private Sub Button1_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Button1.ClickTry
If Me.TextBox1.Text = "http://" Then
MessageBox.Show("請輸入正確的URL!")
Return
End If
Dim urld As String
Dim i As Integer
Dim dfile As New WebClient
Me.SaveFileDialog1.ShowDialog()
fpath = SaveFileDialog1.FileName
Label3.Text = "文件保存在:" & fpath
urld = Me.TextBox1.Text
Me.Timer1.Enabled = True
dfile.DownloadFile(urld, fpath.Substring
(Me.TextBox1.Text.ToString.LastIndexOf("."), 4))Me.Timer1.Enabled = False
Catch ex As Exception
MessageBox.Show(ex.Message)
Return
Application.Exit()
End Try
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Timer1.TickDim th3 As New th2
Dim tt As New System.Threading.Thread(AddressOf th3.timeth)
'實例化線程類
tt.Start() '啟動線程
Label2.Text = th3.downk '顯示下載文件的大小
'進行計算下載速度
Static k As Integer
Dim p, downspeed
p = k
k = p + 1
p = k
Dim form As New DownLoad
Dim fileinfo As New System.IO.FileInfo(form.fpath)
downspeed = fileinfo.Length()
downspeeddownspeed = downspeed / p
Label4.Text = "當前下載速度是" & downspeed & "k/m"
End Sub
End Class
Public Class th2
Public Shared downk As String
Dim form As New DownLoad
Dim fileinfo As New System.IO.FileInfo(form.fpath)
Dim fsize As Long
Public Sub timeth()
If fileinfo.Exists = True Then
fsize = fileinfo.Length()
downk = "以下載文件" & fsize & "k"
End If
End Sub
End Class
看完上述內容,你們對VB.NET下載程序實現代碼怎么編寫有進一步的了解嗎?如果還想了解更多知識或者相關內容,請關注億速云行業資訊頻道,感謝大家的支持。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。