码迷,mamicode.com
首页 > Windows程序 > 详细

C#进度条

时间:2014-11-18 23:56:11      阅读:253      评论:0      收藏:0      [点我收藏+]

标签:style   blog   io   ar   color   os   sp   div   on   

进度条赋值

 1         public void SetProgressValue(int value)
 2         {
 3             if (this.InvokeRequired)
 4             {
 5                 Action<Int32> stepHandle = new Action<int>(SetProgressValue);
 6                 this.Invoke(stepHandle, new object[] { value });
 7             }
 8             else
 9             {
10                 this.progressBarOfCreateDatabase.Value = value;
11                 this.label1.Text = "初始化中 :" + value.ToString() + "%";
12                 if (value == this.progressBarOfCreateDatabase.Maximum) this.Close();
13             }
14         }

耗时操作

 1         void ThreadStartCallback()
 2         {
 3             Action createCallback = SDYF.TCRC.Bussiness.Commander.CreateDB;//耗时操作
 4             IAsyncResult asyncResult = createCallback.BeginInvoke(null, null);
 5             Int32 i = 0;
 6             while (!asyncResult.IsCompleted)
 7             {
 8                 if (i < 99)
 9                 {
10                     i++;
11                 }
12                 Thread.Sleep(40);
13                 SetProgressValue(i);
14             }
15             SetProgressValue(100);
16         }

开启线程

1         private void CreateDatabase_Load(object sender, EventArgs e)
2         {
3             new System.Threading.Thread(new System.Threading.ThreadStart(ThreadStartCallback)).Start();
4         }

 

C#进度条

标签:style   blog   io   ar   color   os   sp   div   on   

原文地址:http://www.cnblogs.com/Ares945/p/progressBar.html

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