今天就跟大家聊聊有关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进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。