成都创新互联网站制作重庆分公司

VB.NET下载程序实现代码怎么编写

今天就跟大家聊聊有关VB.NET下载程序实现代码怎么编写,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。

创新互联公司坚持“要么做到,要么别承诺”的工作理念,服务领域包括:网站设计、做网站、企业官网、英文网站、手机端网站、网站推广等服务,满足客户于互联网时代的建宁网站设计、移动媒体设计的需求,帮助企业找到有效的互联网解决方案。努力成为您成熟可靠的网络建设合作伙伴!

对于VB.NET语言的应用来说,其中有很多小技巧值得我们去掌握,来充实我们的开发经验,以提高编程效率。比如VB.NET下载程序的实现,就是其中一个很有用的编程技巧,能帮助我们很好的解决开发中所遇到的相关问题。

VB.NET下载程序代码示例:

  1. Public Shared fpath As String  

  2. Dim fsize As Long  

  3. Private Sub Button1_Click(ByVal sender As System.Object, 
    ByVal e As System.EventArgs) Handles Button1.Click  

  4. Try  

  5. If Me.TextBox1.Text = "http://" Then  

  6. MessageBox.Show("请输入正确的URL!")  

  7. Return  

  8. End If  

  9. Dim urld As String  

  10. Dim i As Integer  

  11. Dim dfile As New WebClient  

  12. Me.SaveFileDialog1.ShowDialog()  

  13. fpath = SaveFileDialog1.FileName  

  14. Label3.Text = "文件保存在:" & fpath  

  15. urld = Me.TextBox1.Text  

  16. Me.Timer1.Enabled = True 

  17. dfile.DownloadFile(urld, fpath.Substring
    (Me.TextBox1.Text.ToString.LastIndexOf("."), 4))  

  18. Me.Timer1.Enabled = False 

  19. Catch ex As Exception  

  20. MessageBox.Show(ex.Message)  

  21. Return  

  22. Application.Exit()  

  23. End Try  

  24. End Sub 

  1. Private Sub Timer1_Tick(ByVal sender As System.Object, 
    ByVal e As System.EventArgs) Handles Timer1.Tick  

  2. Dim th3 As New th2  

  3. Dim tt As New System.Threading.Thread(AddressOf th3.timeth) 

  4. '实例化线程类   

  5. tt.Start() '启动线程   

  6. Label2.Text = th3.downk '显示下载文件的大小   

  7. '进行计算下载速度   

  8. Static k As Integer  

  9. Dim p, downspeed  

  10. p = k 

  11. k = p + 1  

  12. p = k 

  13. Dim form As New DownLoad  

  14. Dim fileinfo As New System.IO.FileInfo(form.fpath)  

  15. downspeed = fileinfo.Length()  

  16. downspeeddownspeed = downspeed / p  

  17. Label4.Text = "当前下载速度是" & downspeed & "k/m"  

  18. End Sub  

  19. End Class  

  20. Public Class th2  

  21. Public Shared downk As String  

  22. Dim form As New DownLoad  

  23. Dim fileinfo As New System.IO.FileInfo(form.fpath)  

  24. Dim fsize As Long  

  25. Public Sub timeth()  

  26. If fileinfo.Exists = True Then  

  27. fsize = fileinfo.Length()  

  28. downk = "以下载文件" & fsize & "k"  

  29. End If  

  30. End Sub  

  31. End Class 

看完上述内容,你们对VB.NET下载程序实现代码怎么编写有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注创新互联行业资讯频道,感谢大家的支持。


分享名称:VB.NET下载程序实现代码怎么编写
标题来源:http://cxhlcq.com/article/jggosp.html

其他资讯

在线咨询

微信咨询

电话咨询

028-86922220(工作日)

18980820575(7×24)

提交需求

返回顶部