VB.NET下载程序实现代码怎么编写
今天就跟大家聊聊有关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下载程序实现代码怎么编写有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注创新互联行业资讯频道,感谢大家的支持。
本文名称:VB.NET下载程序实现代码怎么编写
转载源于:http://hbruida.cn/article/jggosp.html