c#下载进度条
来源:互联网 发布:python和php学哪个 编辑:程序博客网 时间:2024/05/16 16:00
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 WebClientUpload
{
public partial class Form3 : Form
{
WebClient c;
public Form3()
{
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");
this.Close();
}
private void btnDownload_Click(object sender, EventArgs e)
{
}
void c_DownloadProgressChanged(object sender, System.Net.DownloadProgressChangedEventArgs e)
{
progressBar1.Value = e.ProgressPercentage;
this.label1.Text = "已完成:" + progressBar1.Value.ToString()+"%";
}
private void btnQuit_Click(object sender, EventArgs e)
{
}
private void Form3_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
//上传文件
c.DownloadFileAsync(new Uri("d:\\download\\阿甘正传.rm"), @"e:\11.rm");
}
private void button2_Click(object sender, EventArgs e)
{
//取消上传
if (c != null)
{
c.CancelAsync();
}
Close();
}
}
}
附:另种进度条控制方案:
Form1调用 Form2(进度条窗体)
Form2 pj = new Form2();
pj.Show();
//开始处理大量耗时工作
string sor = "";
int j = 100000;
for (int i = 0; i < j; i++)
{
sor += i.ToString();
if (i % (j / 100) == 0)
{
pj.progressBar1.Value++;
pj.label2.Text = "已完成:" + string.Format("{0:p}", (double)pj.progressBar1.Value / 100);
Application.DoEvents();
}
}
//工作完成,关闭进度条窗体
pj.Close();
- c#下载进度条
- c# 实现进度条下载文件
- C# 下载带进度条代码(普通进度条)
- C# Winform下载文件并显示进度条
- C# Winform下载文件并显示进度条
- C#多线程进度条示例源码下载
- 下载进度条
- 下载进度条
- 下载进度条
- C#进度条
- C#进度条
- c# 进度条
- ajax进度条 异步下载进度条
- FlashGet下载风格进度条
- Android更新下载进度条
- android 下载 进度条
- 文件下载 进度条
- Android更新下载进度条
- Oracle协议适配器错误解决办法
- Ubuntu 下使用命令行安装QT
- 使用C#作为客户端的PHP服务器上传文件
- datepick
- File类
- c#下载进度条
- 转自科学网:《评论:“副教授,我缺少的是什么?”》
- poj2586
- 程序员笑话1
- zookeeper集群的配置和测试
- Android 音频 Native API OpenSL ES 简要介绍
- [leetcode]Maximum Subarray
- 信号和槽使用时各种函数的实际调用顺序
- 黑马程序员---java基础语法1