[C#] 纯文本查看 复制代码 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;
using System.IO;
namespace 下载器
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string url = "http://dldir1.qq.com/qqfile/qq/QQ2013/2013Beta5/6966/QQ2013Beta5.exe";//下载地址,这里以QQ为例了
WebClient Http = new WebClient();
Http.Proxy = null;
Http.DownloadFileCompleted += new AsyncCompletedEventHandler(Http_DownloadFileCompleted);
Http.DownloadProgressChanged += new DownloadProgressChangedEventHandler(Http_DownloadProgressChanged);
Http.DownloadFileAsync(new Uri(url), Application.StartupPath +"\\" +Path.GetFileName(url));
}
void Http_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
progressBar1.Value = e.ProgressPercentage;
}
void Http_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
{
MessageBox.Show("下载完成");
}
}
}
界面自己设计一个按钮 一个进度条就OK了 |