在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Net; namespace WindowsTreeViewDemo { /// <summary> /// 2011-06-25 /// 涂聚文 QQ天气预报 /// </summary> public partial class Form1 : Form { WebClient webClient = new WebClient(); public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { } /// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button1_Click(object sender, EventArgs e) { webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed); webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged); webClient.DownloadFileAsync(new Uri("http://weather.qq.com/inc/ss1.htm"), @"c:\201106021ss1.html"); } /// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ProgressChanged(object sender, DownloadProgressChangedEventArgs e) { progressBar1.Value = e.ProgressPercentage; this.label1.Text = "已完成:" + progressBar1.Value.ToString() + "%"; } /// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Completed(object sender, AsyncCompletedEventArgs e) { MessageBox.Show("Download completed!"); } /// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button2_Click(object sender, EventArgs e) { //取消上传 if (webClient != null) { webClient.CancelAsync(); } Close(); } } } |
请发表评论