1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
| Public Class Form1
Private wc As New WebClient
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
TextBox1.Clear()
TextBox1.Paste()
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim folder As New FolderBrowserDialog With {
.Description = "Veuillez sélectionner une destination !",
.ShowNewFolderButton = True,
.RootFolder = Environment.SpecialFolder.Desktop}
If folder.ShowDialog = Windows.Forms.DialogResult.OK Then
TextBox3.Text = folder.SelectedPath
Else : Exit Sub
End If
End Sub
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
If String.IsNullOrEmpty(TextBox1.Text) Then
MsgBox("Veuillez entrer un URL", MsgBoxStyle.Exclamation, "Erreur")
ElseIf String.IsNullOrEmpty(TextBox2.Text) Then
MsgBox("Veuillez entrer un nom du fichier.", MsgBoxStyle.Exclamation, "Erreur")
ElseIf String.IsNullOrEmpty(TextBox3.Text) Then
MsgBox("Veuillez entrer une destination.", MsgBoxStyle.Exclamation, "Erreur")
Else
wc = New WebClient()
AddHandler wc.DownloadFileCompleted, AddressOf Completed
AddHandler wc.DownloadProgressChanged, AddressOf ProgressChanged
Try
wc.DownloadFileAsync(New Uri(TextBox1.Text), Path.Combine(TextBox3.Text, TextBox2.Text))
Catch ex As Exception
wc.CancelAsync()
MsgBox(ex.ToString, MsgBoxStyle.Critical, "Erreur")
End Try
End If
End Sub
Private Sub Completed(sender As Object, e As AsyncCompletedEventArgs)
If e.Cancelled = True Then
MessageBox.Show("Le téléchargement a été annulé.")
Else
MessageBox.Show("Téléchargement terminé!")
Progressbar1.value = 0
End If
End Sub
Private Sub ProgressChanged(sender As Object, e As DownloadProgressChangedEventArgs)
Progressbar1.value = e.ProgressPercentage
Label1.Text = String.Format("{0} MB's / {1} MB's", (e.BytesReceived / 1024 / 1024).ToString("0.00"), (e.TotalBytesToReceive / 1024 / 1024).ToString("0.00"))
End Sub
End Class |
Partager