对于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.Click- Try
 - 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.Tick- Dim th2 As New th1
 - Dim tt As New System.Threading.Thread(AddressOf th2.timeth)
 - '实例化线程类
 - tt.Start() '启动线程
 - Label2.Text = th2.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 th1
 - 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://www.csdahua.cn/qtweb/news12/372962.html
            
网站建设、网络推广公司-快上网,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 快上网