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
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
  4. Private Sub DownloadButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DownloadButton.Click
  6.     httpclient = New WebClient
  7.     Dim sourceURL = TextBox1.Text
  8.     Dim filedir = TextBox2.Text
  9.     ProgressBar1.Value = 0
  10.     ProgressBar1.Maximum = 100
  12.     Try
  13.         httpclient.DownloadFileAsync(New Uri(sourceURL), (filedir))
  15.     Catch ex As Exception
  17.         MessageBox.Show("Error while  downloding", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
  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.