您好,登錄后才能下訂單哦!
今天就跟大家聊聊有關(guān)VB.NET下載程序?qū)崿F(xiàn)代碼怎么編寫,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結(jié)了以下內(nèi)容,希望大家根據(jù)這篇文章可以有所收獲。
對于VB.NET語言的應(yīng)用來說,其中有很多小技巧值得我們?nèi)フ莆?,來充?shí)我們的開發(fā)經(jīng)驗(yàn),以提高編程效率。比如VB.NET下載程序的實(shí)現(xiàn),就是其中一個很有用的編程技巧,能幫助我們很好的解決開發(fā)中所遇到的相關(guān)問題。
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)
'實(shí)例化線程類
tt.Start() '啟動線程
Label2.Text = th3.downk '顯示下載文件的大小
'進(jìn)行計(jì)算下載速度
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 = "當(dāng)前下載速度是" & 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
看完上述內(nèi)容,你們對VB.NET下載程序?qū)崿F(xiàn)代碼怎么編寫有進(jìn)一步的了解嗎?如果還想了解更多知識或者相關(guān)內(nèi)容,請關(guān)注億速云行業(yè)資訊頻道,感謝大家的支持。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。