您的位置:首页 > 编程语言 > C#

C#使用进度条,并用线程模拟真实数据 ProgressBar用法

2011-09-16 17:44 567 查看




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...";
            }
        }

        private void myStartingMethod()
        {
            for (int i = 1; i <= 100; i++)
            {

                prcBar.Value = i;

            }
        }

    }
}


转:http://www.piaoyi.org/c-sharp/C-ProgressBar.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐