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

          step2:將對(duì)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:實(shí)例化委托并調(diào)用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:讓子線程執(zhí)行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) 評(píng)論(0)  編輯  收藏 所屬分類: .Net
          主站蜘蛛池模板: 彭州市| 文昌市| 左贡县| 宿州市| 克什克腾旗| 杨浦区| 马龙县| 巴林左旗| 云龙县| 西吉县| 巴彦县| 扶沟县| 茶陵县| 惠水县| 垫江县| 江门市| 福海县| 慈溪市| 嫩江县| 河池市| 乌拉特后旗| 若尔盖县| 渭源县| 余江县| 金平| 神农架林区| 利辛县| 吐鲁番市| 云和县| 广安市| 新建县| 富源县| 察哈| 乌拉特中旗| 天全县| 古丈县| 壤塘县| 兴宁市| 巩义市| 鱼台县| 北流市|