step1:定義委托
          private delegate void loadingRun(int step);

          step2:將對UI的操作封裝成方法
          private void doUpdate(int step)
                  {
                      
          if (step == 1)
                      {
                          
          this.checkBox1.Checked = true;
                          
          this.checkBox1.Font = new System.Drawing.Font("MS UI Gothic", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(128)));
                          
          this.checkBox2.Font = new System.Drawing.Font("MS UI Gothic", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(128)));
                      }
                      
          else if (step == 2)
                      {
                          
          this.checkBox2.Checked = true;
                          
          this.checkBox2.Font = new System.Drawing.Font("MS UI Gothic", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(128)));
                          
          this.checkBox3.Font = new System.Drawing.Font("MS UI Gothic", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(128)));
                      }
                      
          else if (step == 3)
                      {
                          
          this.checkBox3.Checked = true;
                          
          this.checkBox3.Font = new System.Drawing.Font("MS UI Gothic", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(128)));
                          
          this.checkBox4.Font = new System.Drawing.Font("MS UI Gothic", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(128)));
                      }
                      
          else if (step == 4)
                      {
                          
          this.checkBox4.Checked = true;
                          
          this.checkBox4.Font = new System.Drawing.Font("MS UI Gothic", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(128)));
                          
          this.Close();
                      }
                  }

          step3:實例化委托并調用doUpdate
          public void run()
                  {
                      loadingRun load 
          = new loadingRun(doUpdate);

                      
          //do something

                      
          this.Invoke(load, 1);

                      
          //do something

                      
          this.Invoke(load, 2);

                      
          //do something

                      
          this.Invoke(load, 3);

                      
          //do something

                      
          this.Invoke(load, 4);
                  }

          step4:讓子線程執行run
          private void init()
                  {
                      ThreadStart ts 
          = new ThreadStart(run);
                      Thread runThread 
          = new Thread(ts);
                      runThread.Start();
                  }

          ========================================分割線=============以下為完整代碼============================================
          using System;
          using System.Collections.Generic;
          using System.ComponentModel;
          using System.Data;
          using System.Drawing;
          using System.Linq;
          using System.Text;
          using System.Windows.Forms;
          using System.Threading;

          namespace WindowsFormsApplication1
          {
              
          public partial class LoadingTest : Form
              {
                  
          private delegate void loadingRun(int step);

                  
          public LoadingTest()
                  {
                      InitializeComponent();
                      init();
                  }

                  
          private void init()
                  {
                      ThreadStart ts 
          = new ThreadStart(run);
                      Thread runThread 
          = new Thread(ts);
                      runThread.Start();
                  }

                  
          public void run()
                  {
                      loadingRun load 
          = new loadingRun(doUpdate);

                      
          //do something

                      
          this.Invoke(load, 1);

                      
          //do something

                      
          this.Invoke(load, 2);

                      
          //do something

                      
          this.Invoke(load, 3);

                      
          //do something

                      
          this.Invoke(load, 4);
                  }

                  
          private void doUpdate(int step)
                  {
                      
          if (step == 1)
                      {
                          
          this.checkBox1.Checked = true;
                          
          this.checkBox1.Font = new System.Drawing.Font("MS UI Gothic", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(128)));
                          
          this.checkBox2.Font = new System.Drawing.Font("MS UI Gothic", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(128)));
                      }
                      
          else if (step == 2)
                      {
                          
          this.checkBox2.Checked = true;
                          
          this.checkBox2.Font = new System.Drawing.Font("MS UI Gothic", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(128)));
                          
          this.checkBox3.Font = new System.Drawing.Font("MS UI Gothic", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(128)));
                      }
                      
          else if (step == 3)
                      {
                          
          this.checkBox3.Checked = true;
                          
          this.checkBox3.Font = new System.Drawing.Font("MS UI Gothic", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(128)));
                          
          this.checkBox4.Font = new System.Drawing.Font("MS UI Gothic", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(128)));
                      }
                      
          else if (step == 4)
                      {
                          
          this.checkBox4.Checked = true;
                          
          this.checkBox4.Font = new System.Drawing.Font("MS UI Gothic", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(128)));
                          
          this.Close();
                      }
                  }
              }
          }

          posted on 2011-09-21 10:24 Ying-er 閱讀(423) 評論(0)  編輯  收藏 所屬分類: .Net
          主站蜘蛛池模板: 永德县| 安多县| 荔波县| 沧州市| 邵阳县| 蒙自县| 秭归县| 布拖县| 杭州市| 美姑县| 七台河市| 修武县| 从化市| 鹰潭市| 德惠市| 万荣县| 会宁县| 丰城市| 西平县| 威宁| 岐山县| 柳江县| 鹿邑县| 嘉祥县| 兴隆县| 潮安县| 搜索| 宜州市| 屯门区| 乳山市| 武鸣县| 鹤峰县| 丽江市| 克山县| 新密市| 莱西市| 河南省| 文水县| 盱眙县| 多伦县| 舟曲县|