zoukankan      html  css  js  c++  java
  • C#使用进度条,并用线程模拟真实数据 ProgressBar用法(转)

    using System;  
    using System.Collections.Generic;  
    using System.ComponentModel;  
    using System.Data;  
    using System.Drawing;  
    using System.Linq;  
    using System.Text;  
    using System.Threading;  
    using System.Windows.Forms;  
      
    namespace jmyd.form  
    {  
        public partial class ProgressBarForm : Form  
        {  
            public ProgressBarForm()  
            {  
                InitializeComponent();  
            }  
             
            private void ProgressBarForm_Shown(object sender, EventArgs e)  
            {  
      
                Thread myThread = new System.Threading.Thread(new ThreadStart(Send));  
      
                myThread.IsBackground = true;  
                myThread.Start();  
            }  
      
            //模拟进度条  
            private void Send()  
            {  
                int i = 0;  
                while (i <= 100)  
                {  
                    //显示进度信息  
                    this.ShowPro(i);  
                    if (i == 100)  
                    {  
                        i = 0;  
                    }  
                    i++; //模拟发送多少  
                    Thread.Sleep(500);  
                }  
                Thread.CurrentThread.Abort();  
            }  
            private delegate void ProgressBarShow(int i);  
            private void ShowPro(int value)  
            {  
                if (this.InvokeRequired)  
                {  
                    this.Invoke(new ProgressBarShow(ShowPro), value);  
                }  
                else  
                {  
                    this.prcBar.Value = value;  
                    this.label1.Text = value + "% Processing...";  
                }  
            }    
        }  
    }

    这个是在线程中更新进度条的,但是C#还有其他的方法更新进度条,有时间进一步研究。

  • 相关阅读:
    Cheatsheet: 2013 12.01 ~ 12.16
    Cheatsheet: 2013 11.12 ~ 11.30
    Cheatsheet: 2013 11.01 ~ 11.11
    Cheatsheet: 2013 10.24 ~ 10.31
    Cheatsheet: 2013 10.09 ~ 10.23
    Cheatsheet: 2013 10.01 ~ 10.08
    Cheatsheet: 2013 09.22 ~ 09.30
    Cheatsheet: 2013 09.10 ~ 09.21
    Cheatsheet: 2013 09.01 ~ 09.09
    Cheatsheet: 2013 08.20 ~ 08.31
  • 原文地址:https://www.cnblogs.com/sowhat4999/p/4989173.html
Copyright © 2011-2022 走看看