Bom eu fiz um projeto rapidinho com progressbar, basicamente o software faz conexão em um
servidor FTP e realiza um download, é simples mas pode se fazer coisas legais, hahaha tipo um sistema
de update.
In this tutorial I will show how make an application that downloads for ftp
[imgg]https://i.imgur.com/CcX719E.png[/img]
[imgg]https://i.imgur.com/JM18Ouz.png[/img]
'CODIGO EXPLICADO
- Spoiler:
Imports System.Net 'Suporte De Download EMCIMA DA CLASS
'------------------------------------------------CODIGOS ABAIXO DA CLASS----------------------
WithEvents Downloader As New WebClient 'Variavel Global Com A Função Webclient
Dim Download As New Uri("ftp://skycheat.p.ht/update/Bob Marley One Love.mp3") 'Variavel Do Local Do Link Do Download
Dim Local As String = Application.StartupPath & "\Bob Marley One Love.mp3" 'Local Onde o arquivo vai quando terminar o download ou seja na pasta do aplicativo codigo que faz o arquivo ir para pasta Application.StartupPath
'ATENÇÃO ESTE CODIGO VAI NO INICIO DO PROGRAMA
'CODIGO DO BOTÃO DOWNLOAD
Downloader.Credentials = New Net.NetworkCredential("uLOGINFTP", "PASSWORDFTP") 'ATENÇÃO ESTA EM "LOGINFTP" COLOQUE SEU LOGIN FTP E EM "PASSWORDFTP" SENHA DO FTP
Downloader.DownloadFileAsync(Download, Local) 'Downloader , Variaval Global , DownloadFileAsync Função que faz o download "(Download, Local)" Variavel Do Local Do Link
' Sub ' DA VARIAVEL GLOBAL "Downloader_DownloadFileCompleted"
'-----------------------------
ProgressBar1.Value = 0 'Zera a Progressbar
MsgBox("COMPLETE") 'Mensagem que o download termino
End Sub
' Sub De ' Progresso De Download "Downloader_DownloadProgressChanged"
ProgressBar1.Value = ProgressBar1.Value + 1 ' Adiciona 1 PORCENTO NA PROGRESS BAR
If ProgressBar1.Value = ProgressBar1.Value + 1 Then ' Adiciona 1 PORCENTO NA PROGRESS BAR
ElseIf ProgressBar1.Value = 99 Then 'ProgressBar1.Value = 99 VALOR DA PROGRESSBAR 99%
ProgressBar1.Value = 0 'ZERA PROGRESSBAR
' MsgBox("Arquivo baixado 'Este arquivo está na pasta deste programa'", 'MESSAGEM
End If
CODIGO COMPLETO
- Spoiler:
- Imports System.Net
Public Class Form1
WithEvents Downloader As New WebClient
Dim Download As New Uri("ftp://skycheat.p.ht/update/Bob Marley One Love.mp3")
Dim Local As String = Application.StartupPath & "\Bob Marley One Love.mp3"
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Downloader.Credentials = New Net.NetworkCredential("uLOGINFTP", "PASSWORDFTP")
Downloader.DownloadFileAsync(Download, Local)
End Sub
Private Sub Downloader_DownloadFileCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.AsyncCompletedEventArgs) Handles Downloader.DownloadFileCompleted
ProgressBar1.Value = 0
MsgBox("COMPLETE")
End Sub
Private Sub Downloader_DownloadProgressChanged(ByVal sender As Object, ByVal e As System.Net.DownloadProgressChangedEventArgs) Handles Downloader.DownloadProgressChanged
ProgressBar1.Value = ProgressBar1.Value + 1
If ProgressBar1.Value = ProgressBar1.Value + 1 Then
ElseIf ProgressBar1.Value = 99 Then
ProgressBar1.Value = 0
End If
End Sub
End Class
RESULT
- Attachments
- Downloader.zip
- You don't have permission to download attachments.
- (181 Kb) Downloaded 2 times