Avatar billede kris914g1 Nybegynder
28. juni 2013 - 15:51

Kan man lave multiple downloads med checkboxes? i vb.net

hej er begyndt at bruge WebClient i vp.net først startede jeg med at lave en knap som lavede et download men kan man tilknytte det til checkboxes? fx hvis jeg havde 10 checkboxes så kunne jeg have 10 downloads? kender tror ikke jeg kender koden men har prøvet men når jeg fx har valgt to checkboxes så beder den om hvor de 2 filer skal saves men så er der kun 1 som bliver downloadet? nogen som ved hvad jeg gør galt?

kode:

Imports System.Net
Imports System.IO
Imports System.Diagnostics
Public Class Form1

    Private WithEvents WC As WebClient
#Region "Download RateVariables"
    Private ChangeInAmount As Integer
    Private PreviousAmount As Integer
    Private NextCheck As DateTime
#End Region


    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        setstatus("0 kb", "0kb", "0%", "0kb/s")
        WC = New WebClient
    End Sub
    Private Sub setstatus(CurDownload As String, ByVal TotalDownload As String, ByVal Percentage As String, ByVal Rate As String)
        Label1.Text = "Downloaded : " & CurDownload
        Label2.Text = "Download Size : " & TotalDownload
        Label3.Text = "Rate : " & Rate
        Label4.Text = "Percentage : " & Percentage
    End Sub
    Public Function CalculateRate(ByVal Input As Integer) As String
        Return Processbytes(Input) & "/s"
    End Function

    Public Function Processbytes(ByVal Input As Integer) As String

        'Check if the file is 1GB or more
        If Input >= 1073741824 Then
            Return Math.Round(CDbl(Input / 1073741824), 2) & " GB"
        Else
            'Check for MB
            If Input >= 1048576 Then
                Return Math.Round(CDbl(Input / 1048576), 2) & " MB"
            Else
                'Can only be in KB
                Return Math.Round(CDbl(Input / 1024), 2) & " KB"
            End If

        End If

    End Function

    Private Function CDb1(p1 As Double) As Double
        Throw New NotImplementedException
    End Function

    Private Sub WC_DownloadFileCompleted(sender As Object, e As System.ComponentModel.AsyncCompletedEventArgs) Handles WC.DownloadFileCompleted
        ProgressBar1.Value = 0
        ProgressBar1.Maximum = 0
        ChangeInAmount = 0
        PreviousAmount = 0
        NextCheck = Now.AddSeconds(1)
    End Sub

    Private Sub WC_DownloadProgressChanged(sender As Object, e As DownloadProgressChangedEventArgs) Handles WC.DownloadProgressChanged
        Try
            If Now > NextCheck Then
                ChangeInAmount = e.BytesReceived - PreviousAmount
                PreviousAmount = e.BytesReceived
                NextCheck.AddSeconds(1)
            End If
            Dim Rate As String = CalculateRate(ChangeInAmount)
            ProgressBar1.Maximum = e.TotalBytesToReceive
            ProgressBar1.Value = e.BytesReceived
            setstatus(Processbytes(e.BytesReceived), Processbytes(e.TotalBytesToReceive), e.ProgressPercentage, Rate)
        Catch
        End Try
    End Sub
   
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        If CheckBox1.Checked = True Then




            Dim webAddress As String = "url"
            Dim SFD As New SaveFileDialog
            If SFD.ShowDialog() = DialogResult.OK Then
                WC.DownloadFileAsync(New Uri("url"), SFD.FileName)
            End If

        End If

        If CheckBox2.Checked = True Then


            Dim webAddress As String = "url"
            Dim SFD As New SaveFileDialog
            If SFD.ShowDialog() = DialogResult.OK Then
                WC.DownloadFileAsync(New Uri("url"), SFD.FileName)
            End If

        End If

        If CheckBox3.Checked = True Then


            Dim webAddress As String = "url"
            Dim SFD As New SaveFileDialog
            If SFD.ShowDialog() = DialogResult.OK Then
                WC.DownloadFileAsync(New Uri("url"), SFD.FileName)
            End If

        End If
    End Sub
End Class
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester