By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,285 Members | 1,659 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,285 IT Pros & Developers. It's quick & easy.

Visual Basic 2012 File Downloader

P: 1
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:

Expand|Select|Wrap|Line Numbers
  1. Imports System.Net
  2. Private WithEvents httpclient As WebClient
  3.  
  4. Private Sub DownloadButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DownloadButton.Click
  5.  
  6.     httpclient = New WebClient
  7.     Dim sourceURL = TextBox1.Text
  8.     Dim filedir = TextBox2.Text
  9.     ProgressBar1.Value = 0
  10.     ProgressBar1.Maximum = 100
  11.  
  12.     Try
  13.         httpclient.DownloadFileAsync(New Uri(sourceURL), (filedir))
  14.  
  15.     Catch ex As Exception
  16.  
  17.         MessageBox.Show("Error while  downloding", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
  18.  
  19.     End Try
  20. End Sub


Grateful for any reply. Thank in advance
Jul 2 '13 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.