Visual Basic 2012 File Downloader

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kostakostvb
    New Member
    • Jul 2013
    • 1

    Visual Basic 2012 File Downloader

    Hello,
    I am creating a file downloader in Visual Basic 2012.
    It works well, but when I click the red X button, it closes whether the download has finished or not. Thus,
    I am looking for code that disables the X button at a certain time. I mean, I do not want it always disabled,
    just when a file is being downloaded.
    What is more, I am also looking for a code for creating
    a Cancel button (to cancel file download).

    Here's the file download code:

    Code:
    Imports System.Net
    Private WithEvents httpclient As WebClient
    
    Private Sub DownloadButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DownloadButton.Click
            
        httpclient = New WebClient
        Dim sourceURL = TextBox1.Text
        Dim filedir = TextBox2.Text
        ProgressBar1.Value = 0
        ProgressBar1.Maximum = 100
                
        Try
            httpclient.DownloadFileAsync(New Uri(sourceURL), (filedir))
                
        Catch ex As Exception
                
            MessageBox.Show("Error while  downloding", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
                    
        End Try
    End Sub


    Grateful for any reply. Thank in advance
    Last edited by Frinavale; Jul 2 '13, 01:33 PM. Reason: Added code tags. Please post code in code tags.
Working...