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

发布时间:2021-10-27 18:04:39 作者:柒染
来源:亿速云 阅读:120

今天就跟大家聊聊有关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下载程序实现代码怎么编写有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注亿速云行业资讯频道,感谢大家的支持。

推荐阅读:
  1. MapReduce编写wordcount程序代码实现
  2. c程序编写x的y次方的实现代码

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

vb.net

上一篇:VB.NET拆分合并语句的应用技巧有哪些

下一篇:Mysql数据分组排名实现的示例分析

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》