点击这里给我发消息 点击这里给我发消息

网站建设技术应用:winform 异步程序进度条的实现

添加时间:2010-4-10
    相关阅读: 网站建设 技术 程序 网站 建设
  这里用到的winform进度条控件,我是从网上找的,感觉控件总体上来说很美观,下载地址忘了在哪里了,所以各位看官可以去网上找一款心仪的进度条控件,好,废话就说到这里,我们开始了我们今天的任务。
第一步:把进度条控件拖拽到我们的form窗口中,设置下控件的属性,如:Step(步长),Maxinum(最大值),Mininum(最小值),MainColor(主颜色)
 
第二步:双击我们要开始运行的Button按钮
 
        private void btnTongBu_Click(object sender, EventArgs e)
        {
            new System.Threading.Thread(new System.Threading.ThreadStart(StartProgress)).Start();
        }
在线程中开始执行我们需要开始显示进度条的工作任务。
 
        public void StartProgress()
        {
            ProgressStart progress= new ProgressStart (this);
            progress.onProgress += new ProgressStart .dProgress(dProgress_onProgressStart);
            progress.Start();
        }
 
       

 //更新UI
        void dProgress_onProgressStart(long total, long current)
        {
            if (this.InvokeRequired)
            {
                this.Invoke(new ProgressStart .dProgress(dProgress_onProgressStart), new object[] { total, current });
            }
            else
            {
                this.userControl11.Maximum = (int)total;
                this.userControl11.Value = (int)current;
            }
        }

        /// <summary>
        /// 处理类
        /// </summary>
        public class ProgressStart
        {
            ProductConvertInventory F = null;
            public ProgressStart ( ProductConvertInventory _F)
            {
                F = _F;
            }
            //委托
            public delegate void dProgress(long total, long current);
            //事件
            public event dProgress onProgress;
            //开始模拟工作
            public void Start()
            {
               if(F!=null)
               {
                   if (this.F.lblInventionID.Text != "")
                   {
                       if (this.F.lblComputationID.Text != "")
                       {
                           RM.BLL.db_product productBll = new RM.BLL.db_product();
                           DataTable dt = productBll.GetList();
                           int strNums = 0;
                           if (dt.Rows.Count > 0)
                           {
                               for (int i = 0; i < dt.Rows.Count; i++)
                               {
                                         
                                 int saa = ((i + 1) * 100 / dt.Rows.Count);
                                   if (onProgress!= null)
                                       onProgress(100, saa);
                                   System.Threading.Thread.Sleep(30);                               }
               }
            }
        }
咨询热线:020-85648757 85648755 85648616 0755-27912581 客服:020-85648756 0755-27912581 业务传真:020-32579052
广州市网景网络科技有限公司 Copyright◎2003-2008 Veelink.com. All Rights Reserved.
广州商务地址:广东省广州市黄埔大道中203号(海景园区)海景花园C栋501室
= 深圳商务地址:深圳市宝源路华丰宝源大厦606
研发中心:广东广州市天河软件园海景园区 粤ICP备05103322号 工商注册