等待表單
啟動畫面管理器允許您創(chuàng)建一個等待表單(WaitForm) ,一種旨在識別皮膚的表單,用于指示耗時的操作。

主要功能包括:
- 動畫的連續(xù)進度指示器。
- 您可以在代碼中顯示關(guān)閉等待表單。
- 設(shè)計時自定義。
- 通過命令與等待表單進行交互。
- 默認外觀設(shè)置取決于皮膚。

創(chuàng)建和自定義等待表單
- 將SplashScreenManager 組件拖放到表單上,右鍵單擊Visual Studio托盤中的組件,然后選擇Add Wait Form。

- SplashScreenManager將新的WaitForm添加到您的項目。

- 要在設(shè)計時查看和自定義等待表單,請在Solution Explorer中雙擊WaitForm1.cs(WaitForm1.vb)文件。

- 使用屬性網(wǎng)格更改內(nèi)置ProgressPanel的顯示設(shè)置,此面板顯示動畫進度指示器和標簽。

注意:如果需要使用自定義類擴展WaitForm1.cs/.vb文件,請確保封裝Wait Form的類在這些文件中排在第一位。
顯示和隱藏等待表單
等待表單不會在主表單啟動時自動顯示,您可以使用以下方法顯示和關(guān)閉等待表單,具體取決于等待表單是否處于激活狀態(tài)(已分配給 SplashScreenManager.ActiveSplashFormTypeInfo屬性)。
- 目標等待表單處于激活狀態(tài)。

要顯示/關(guān)閉等待表單,請使用非靜態(tài)的SplashScreenManager.ShowWaitForm和SplashScreenManager.CloseWaitForm方法。
C#:
splashScreenManager1.ShowWaitForm(); //... splashScreenManager1.CloseWaitForm();
VB.NET:
splashScreenManager1.ShowWaitForm() splashScreenManager1.ShowWaitForm() '... splashScreenManager1.CloseWaitForm() splashScreenManager1.CloseWaitForm()
- 目標等待表單未激活。

要顯示/關(guān)閉等待表單,請使用靜態(tài)SplashScreenManager.ShowForm和SplashScreenManager.CloseForm方法,特定的SplashScreenManager.ShowForm方法重載允許您指定淡入淡出效果和等待表單位置。
C#:
SplashScreenManager.ShowForm(typeof(WaitForm1)); //... SplashScreenManager.CloseForm();
VB.NET:
SplashScreenManager.ShowForm(GetType(WaitForm1)) '... SplashScreenManager.CloseForm()
動態(tài)更新等待表單
與其他初始屏幕一樣,等待表單也顯示在單獨的線程中。
使用以下方法從主線程動態(tài)更新顯示等待表單的標題和描述:
您還可以使用SplashScreenManager.SendCommand方法與當前的等待表單進行交互(例如,更新其內(nèi)容)。要處理此方法發(fā)送的命令,請重寫WaitForm.ProcessCommand方法。
使用說明
顯示多個等待表單
如果您的應(yīng)用程序一次只顯示一個等待表單,則可以使用單個SplashScreenManager組件。
若要同時顯示多個等待表單,請使用多個SplashScreenManager組件。
MDI應(yīng)用
在MDI應(yīng)用程序中,不要顯示Control.CreateHandle方法調(diào)用的事件或方法的等待表單 - HandleCreated,Load,MdiChildActivate,OnHandleCreated重載等,否則您的應(yīng)用程序可能會凍結(jié)。
而是,使用以下方法:
- 從事件處理程序中調(diào)用等待表單。
- 使用方法顯示等待表單。
C#:
//Incorrect - the app may freeze private void MdiParent_MdiChildActivate(object sender, EventArgs e) { //... splashScreenManager1.ShowWaitForm(); splashScreenManager1.SetWaitFormCaption("Please wait"); splashScreenManager1.SetWaitFormDescription(description); //... splashScreenManager1.CloseWaitForm(); } //Correct private void MdiParent_MdiChildActivate(object sender, EventArgs e) { BeginInvoke(new Action(() => { //... splashScreenManager1.ShowWaitForm(); splashScreenManager1.SetWaitFormCaption("Please wait"); splashScreenManager1.SetWaitFormDescription(description); //... splashScreenManager1.CloseWaitForm(); })); }
VB.NET :
'Incorrect - the app may crash Private Sub MdiParent_MdiChildActivate(ByVal sender As Object, ByVal e As EventArgs) '... splashScreenManager1.ShowWaitForm() splashScreenManager1.SetWaitFormCaption("Please wait") splashScreenManager1.SetWaitFormDescription(description) '... splashScreenManager1.CloseWaitForm() End Sub 'Correct Private Sub MdiParent_MdiChildActivate(ByVal sender As Object, ByVal e As EventArgs) BeginInvoke(New Action(Sub() '... splashScreenManager1.ShowWaitForm() splashScreenManager1.SetWaitFormCaption("Please wait") splashScreenManager1.SetWaitFormDescription(description) '... splashScreenManager1.CloseWaitForm() End Sub)) End Sub