标签:
private void button1_Click(object sender, EventArgs e) { WebClient webclient = new WebClient(); webclient.Proxy = null; webclient.Encoding = Encoding.UTF8; richTextBox1.AppendText(webclient.DownloadString(textBox1.Text.Trim())); webclient.Dispose(); } private void button2_Click(object sender, EventArgs e) { WebClient webclient = new WebClient(); webclient.Proxy = null; webclient.DownloadFile(textBox2.Text, textBox3.Text); MessageBox.Show("成功!"); webclient.Dispose(); } private void button3_Click(object sender, EventArgs e) { WebClient webclient = new WebClient(); webclient.Proxy = null; webclient.DownloadProgressChanged += webclient_DownloadProgressChanged; webclient.DownloadDataCompleted += webclient_DownloadDataCompleted; webclient.DownloadFileAsync(new Uri(textBox2.Text), textBox3.Text); webclient.Dispose(); } void webclient_DownloadDataCompleted(object sender, DownloadDataCompletedEventArgs e) { MessageBox.Show("成功"); } void webclient_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e) { progressBar1.Value = e.ProgressPercentage; }
使用WebClient类对网页下载源码,对文件下载保存及异步下载并报告下载进度
标签:
原文地址:http://www.cnblogs.com/lunawzh/p/5540589.html