yulei's blog

有梦想更有要有行动,每天前进一小步,那么每年可以迈出一大步 QQ:65072096 MSN:coolsoft2001@sina.com

导航

webClient下载进度条

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;

namespace DownlaodFile
{
public partial class Form1 : Form
{
System.Net.WebClient c ;
public Form1()
{
InitializeComponent();
c
= new System.Net.WebClient();
c.DownloadProgressChanged
+= new System.Net.DownloadProgressChangedEventHandler(c_DownloadProgressChanged);
c.DownloadFileCompleted
+= new AsyncCompletedEventHandler(c_DownloadFileCompleted);
c.Proxy
=WebRequest.DefaultWebProxy;
c.Proxy.Credentials
= new NetworkCredential("admin", "admin_password", "domain");
}

void c_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
{
MessageBox.Show(
"ok");
}

private void btnDownload_Click(object sender, EventArgs e)
{
c.DownloadFileAsync(
new Uri(txtUrl.Text), @"d:"t.dat");
}

void c_DownloadProgressChanged(object sender, System.Net.DownloadProgressChangedEventArgs e)
{
progressBar1.Value
= e.ProgressPercentage;
}

private void btnQuit_Click(object sender, EventArgs e)
{
if (c!=null)
{
c.CancelAsync();
}
Close();
}
}
}

posted on 2009-03-08 13:52  yulei  阅读(2062)  评论(0编辑  收藏  举报