Splash表單(ProgressWindowForm修改)

來源:互聯網
上載者:User

     上篇中寫了一個ProgressWindowForm表單,主要使用線程來處理系統中執行的大資料量操作的一個多線程解決方案,本次將其修改一下,使用線程去處理系統載入過程中的一些處理事項。

     介面圖如下:

     

     這個Splash和原來的ProgressWindowForm的方式一樣,只是修改了其中的少許代碼,首先 就是本表單沒有了以前的取消方法,刪除取消的相關代碼就可以了,第二就是表單不能被強制關閉,也就是說不能使用Alt+F4關閉本表單,這是很簡單的,我在表單中添加了ProcessDialogKey來去除Alt+F4功能,代碼如下:

 1         protected override bool ProcessDialogKey(Keys keyData)
 2         {
 3             switch (keyData)
 4             {
 5                 case Keys.Alt | Keys.F4:
 6                     return true;
 7                 default: 
 8                     break;
 9             }
10             return base.ProcessDialogKey(keyData);
11         }

   使用Splish的方法就和原來ProgressWindowForm的方法是一樣的,主要就是在主表單顯示前,添加如下的代碼:

this.Hide();
SplashWindowForm splashWindowForm = new SplashWindowForm();
splashWindowForm.Text = "測試工作";
System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(SplashDoWork), splashWindowForm);
splashWindowForm.ShowDialog(); 

     SplashDoWork的代碼如下:

        private void SplashDoWork(object status)
        {
            SplashWindowForm splashWindowForm = status as SplashWindowForm;
            try
            {
                splashWindowForm.BeginThread(0, 300);
                for (int i = 0; i < 100; ++i)
                {
                    splashWindowForm.SetDisplayText("載入啟動項1.");
                    splashWindowForm.StepTo(i);
                    if (splashWindowForm.IsAborting)
                    {
                        return;
                    }
                    System.Threading.Thread.Sleep(100);
                    if (splashWindowForm.IsAborting)
                    {
                        return;
                    }
                }

                for (int i = 100; i < 200; ++i)
                {
                    splashWindowForm.SetDisplayText("載入啟動項2.");
                    splashWindowForm.StepTo(i);
                    if (splashWindowForm.IsAborting)
                    {
                        return;
                    }
                    System.Threading.Thread.Sleep(100);
                    if (splashWindowForm.IsAborting)
                    {
                        return;
                    }
                }

                for (int i = 200; i < 300; ++i)
                {
                    splashWindowForm.SetDisplayText("載入啟動項3.");
                    splashWindowForm.StepTo(i);
                    if (splashWindowForm.IsAborting)
                    {
                        return;
                    }
                    System.Threading.Thread.Sleep(100);
                    if (splashWindowForm.IsAborting)
                    {
                        return;
                    }
                }
            }
            catch (Exception exception)
            {
               MessageBox.Show(exception.Message + Environment.NewLine + exception.StackTrace);
            }
            finally
            {
                if (splashWindowForm != null)
                {
                    splashWindowForm.End();
                }
            }
        }

   代碼下載:/Files/zhjp11/ProgressWindowWithSplash.rar

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.