What you need:
- Button
- Progressbar(Make it show text, see properties)
- Label
- Backgroundworker
[php]#Region "Declarations"
'new webclient to for downloading
WithEvents webC As New Net.WebClient
Private apppath As String = Application.StartupPath & "\"
Private filename As String
'avoid the same filename twice
Private i As Integer = 1
'received/total bytes
Private total, current As Integer
'links
Private Const _version As String = "http://version.txt"
Private Const _FileToDL As String = "http://Recorder.exe"
Private Const _log As String = "http://changelog.txt"
#End Region
#Region "Download/Progress"
Private Sub cmdDownload_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdDownload.Click
If cmdDownload.Text = "Download" Then
bgwDownload.RunWorkerAsync()
Else
Process.Start(filename)
Application.Exit()
Me.Close()
End If
End Sub
Private Sub webC_DownloadFileCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.AsyncCompletedEventArgs) Handles webC.DownloadFileCompleted
MsgBox("Download complete." & vbNewLine & vbNewLine _
& "Saved at: " & filename)
cmdDownload.Text = "Start Recorder"
cmdDownload.Enabled = True
End Sub
Private Sub webC_DownloadProgressChanged(ByVal sender As Object, ByVal e As System.Net.DownloadProgressChangedEventArgs) Handles webC.DownloadProgressChanged
current = e.BytesReceived 'bytes i dled already
total = e.TotalBytesToReceive 'total bytes it has to dl
If total <> current Then
cmdDownload.Enabled = False
End If
pbProgress.Value = e.ProgressPercentage
pbProgress.Text = CInt(current / 1024) & "/" & CInt(total / 1024) & " KB received | " & e.ProgressPercentage & " %"
End Sub
Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles bgwDownload.DoWork
webC.DownloadFileAsync(New Uri(_FileToDL), filename)
End Sub
#End Region
#Region "Startup"
Private Sub UpdateApp_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Control.CheckForIllegalCrossThreadCalls = False
Dim cl As New Threading.Thread(AddressOf changelog)
cl.Start()
lblCurV.Text &= Application.ProductVersion
Do While IO.File.Exists(apppath & "Recorder_Updated - " & i & ".exe")
i += 1
Loop
filename = apppath & "Recorder_Updated - " & i & ".exe"
End Sub
Private Sub changelog()
txtChangelog.Text = loadPage(_log)
End Sub
Private Sub newversion()
lblNewV.Text &= loadPage(_version)
End Sub
Private Sub UpdateApp_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown
Dim checkv As New Threading.Thread(AddressOf newversion)
checkv.Priority = Threading.ThreadPriority.Highest
checkv.Start()
End Sub
#End Region [/php]
Fully self-written. Taken from my macro-recorder.
Network.Download Choobs
