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 th2 As New th1  
  3. Dim tt As New System.Threading.Thread(AddressOf th2.timeth) 
  4. '实例化线程类   
  5. tt.Start() '启动线程   
  6. Label2.Text = th2.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 th1  
  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下载程序代码实现
网页URL:http://www.shufengxianlan.com/qtweb/news12/372962.html

网站建设、网络推广公司-创新互联,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联