Ver Mensaje Individual
  #7 (permalink)  
Antiguo 08/08/2012, 20:02
wyrms
 
Fecha de Ingreso: agosto-2012
Mensajes: 5
Antigüedad: 11 años, 9 meses
Puntos: 0
Respuesta: ¿descargar un archivo al darle a un botón, y ver el progreso y velocidad d

bueno ya lo solucione.
aquí el código de 1 botón, los demás es lo mismo, pero con sus direcciones.
Código vb:
Ver original
  1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  2.         Dim client As WebClient = New WebClient
  3.         AddHandler client.DownloadProgressChanged, AddressOf client_ProgressChanged
  4.         AddHandler client.DownloadFileCompleted, AddressOf client_DownloadCompleted
  5.         If IO.Directory.Exists("C:\descargas_launcher") Then
  6.         Else
  7.             On Error Resume Next
  8.             If Err.Number = 0 Then
  9.                 IO.Directory.CreateDirectory("c:\descargas_launcher")
  10.                 MsgBox("El directorio Descargas_launcher ha sido creado", MsgBoxStyle.Exclamation, "Descargado!")
  11.             Else
  12.                 Err.Clear()
  13.             End If
  14.         End If
  15.         If IO.File.Exists("C:\descargas_launcher\archivo.rar") Then
  16.             MsgBox("El archivo ya esta descargado!", MsgBoxStyle.Exclamation, "Descargado!")
  17.         Else
  18.             On Error Resume Next
  19.             If Err.Number = 0 Then
  20.                 client.DownloadFileAsync(New Uri("http://direción.a.descargar.rar"), "C:\descargas_launcher\dirección.a.guardar.rar")
  21.             Else
  22.                 MsgBox(Err.Description)
  23.             End If
  24.             Err.Clear()
  25.             ProgressBar1.Visible = True
  26.             Label1.Visible = True
  27.             Label2.Visible = True
  28.             Label3.Visible = True
  29.             Button1.Text = "Descargando..."
  30.             Button1.Enabled = False
  31.             Button2.Enabled = False
  32.             Button4.Enabled = False
  33.             Button5.Enabled = False
  34.             Button7.Enabled = False
  35.         End If
  36.     End Sub
lo que me faltaría es poner la velocidad de red de descarga en el progressbar para las descargas en kbps.
aquí dejo el código de los medidores como los tengo:
Código vb:
Ver original
  1. Private Sub client_ProgressChanged(ByVal sender As Object, ByVal e As DownloadProgressChangedEventArgs)
  2.         Dim bytesIn As Double = Double.Parse(e.BytesReceived.ToString())
  3.         Dim totalBytes As Double = Double.Parse(e.TotalBytesToReceive.ToString())
  4.         Dim percentage As Double = bytesIn / totalBytes * 100
  5.         Label1.Text = CStr(e.ProgressPercentage & (" %"))
  6.         Label2.Text = CStr(bytesIn / 1024 / 1000 & "  MB")
  7.         Label3.Text = CStr(totalBytes / 1024 / 1000 & "  TOTAL MB")
  8.         ProgressBar1.Value = Int32.Parse(Math.Truncate(percentage).ToString())
  9.     End Sub
muchísimas gracias por todo tu apoyo de verdad, me ha servido mucho.
lo que no se como poner es lo ultimo dicho y lo ultimo que necesito :D.

un saludete.

Última edición por wyrms; 08/08/2012 a las 21:32