码迷,mamicode.com
首页 > 其他好文 > 详细

C# 模式窗口下更新进度条

时间:2014-06-15 16:40:31      阅读:141      评论:0      收藏:0      [点我收藏+]

标签:style   class   blog   code   tar   color   

public partial class frmProcessBar : Form
    {
        public frmProcessBar()
        {
            InitializeComponent();
        }

        public bool Increase(int nValue)
        {
            if (nValue > 0)
            {
                if (progressBar1.Value + nValue < progressBar1.Maximum)
                {
                    progressBar1.Value += nValue;
                    return true;
                }
                else
                {
                    progressBar1.Value = progressBar1.Maximum;
                    this.Close();
                    return false;
                }
            }
            return false;
        }
    }

 

private frmProcessBar myProcessBar = null;
        private delegate bool IncreaseHandle(int nValue);
        private IncreaseHandle myIncrease = null;

private void btnRun_Click(object sender, EventArgs e)
        {
            Thread thdSub = new Thread(new ThreadStart(ThreadFun));
            thdSub.Start();
        }

        private void ShowProcessBar()
        {
            myProcessBar = new frmProcessBar();
            // Init increase event
            myIncrease = new IncreaseHandle(myProcessBar.Increase);
            myProcessBar.ShowDialog();
        }

        private void ThreadFun()
        {
            MethodInvoker mi = new MethodInvoker(ShowProcessBar);
            this.BeginInvoke(mi);
            bool blnIncreased = false;
            object objReturn = null;
            do
            {
                Thread.Sleep(50);
                objReturn = this.Invoke(this.myIncrease,new object[] { 1 });
                blnIncreased = (bool)objReturn;
            }
            while (blnIncreased);
        }

 

C# 模式窗口下更新进度条,布布扣,bubuko.com

C# 模式窗口下更新进度条

标签:style   class   blog   code   tar   color   

原文地址:http://www.cnblogs.com/rinack/p/3785709.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!