• winform 下载文件显示进度和百分比


            /// <summary>
            /// 下载完成
            /// </summary>
            private void DownloadFileCompleted()
            {
                IsComlate = true;
            }
            /// <summary>
            /// 显示进度
            /// </summary>
            /// <param name="val"></param>
            private void DownloadProgressChanged(int val)
            {
                progressBar1.Value = val;
                Persent.Text = val.ToString() + "%";
                progressBar1.PerformStep();
            }
            /// <summary>
            /// 下载文件
            /// </summary>
            /// <param name="url"></param>
            /// <param name="savefile"></param>
            /// <param name="downloadProgressChanged"></param>
            /// <param name="downloadFileCompleted"></param>
            private void DownloadFile(string url, string saveFile, Action<int> downloadProgressChanged, Action downloadFileCompleted)
            {
                WebClient client = new WebClient();
                client.Proxy = null;
                if (downloadProgressChanged != null)
                {
                    client.DownloadProgressChanged += delegate(object sender, DownloadProgressChangedEventArgs e)
                    {
                        this.Invoke(downloadProgressChanged, e.ProgressPercentage);
                    };
                }
                if (downloadFileCompleted != null)
                {
                    client.DownloadFileCompleted += delegate(object sender, AsyncCompletedEventArgs e)
                    {
                        this.Invoke(downloadFileCompleted);
                    };
                }
                client.DownloadFileAsync(new Uri(url), saveFile);
            }
         /// <summary>
         /// 点击下载
         /// </summary>
         /// <param name="sender"></param>
         /// <param name="e"></param>
         private void button1_Click(object sender, EventArgs e)
         {
             DownloadFile("http://www.111cn.net/update.zip", @"F:update.zip", DownloadProgressChanged, null);
         }    
  • 相关阅读:
    centos7下升级SSH
    docker: read tcp 192.168.7.235:36512->54.230.212.9:443: read: connection reset by peer.
    Rancher学习笔记----在UI界面添加主机页面无法正常显示
    Rancher3----安装部署rancher
    Rancher2-----了解什么是rancher以及简单部署
    unity坑-编译错误
    游戏UI系统设计
    使用采样器声明
    着色器数据类型和精度
    着色器编译目标等级
  • 原文地址:https://www.cnblogs.com/a849788087/p/7085245.html
Copyright © 2020-2023  润新知