DevExpress WinForms幫助文檔:表單和用戶控件 -等待表單

點擊獲取DevExpress完整版下載

DevExpress技術交流羣3:700924826      歡迎一起進羣討論

初始屏幕管理器允許您創建一個等待表單(WaitForm) - 一種旨在識別皮膚的表單,用於指示耗時的操作。

DevExpress WinForms幫助文檔

主要功能包括:

  • 動畫的連續進度指示器。
  • 您可以在代碼中顯示關閉等待表單。
  • 設計時自定義。
  • 通過命令與等待表單進行交互。
  • 默認外觀設置取決於皮膚。
DevExpress WinForms幫助文檔

創建和自定義等待表單

SplashScreenManager 組件拖放到窗體上,右鍵單擊Visual Studio托盤中的組件,然後選擇Add Wait Form。

DevExpress WinForms幫助文檔

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

DevExpress WinForms幫助文檔

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

DevExpress WinForms幫助文檔

使用屬性網格更改內置ProgressPanel的顯示設置,此面板顯示動畫進度指示器和標籤。

DevExpress WinForms幫助文檔

注意:如果需要使用自定義類擴展WaitForm1.cs/.vb文件,請確保封裝Wait Form的類在這些文件中排在第一位。

DevExpress WinForms幫助文檔

顯示和隱藏等待表單

等待表單不會在主表單啓動時自動顯示。 您可以使用以下方法顯示和關閉等待表單,具體取決於等待表單是否處於激活狀態(已分配給 SplashScreenManager.ActiveSplashFormTypeInfo屬性)。

  • 目標等待表單處於激活狀態。
DevExpress WinForms幫助文檔

要顯示/關閉等待表單,請使用非靜態的SplashScreenManager.ShowWaitFormSplashScreenManager.CloseWaitForm方法。

C#

splashScreenManager1.ShowWaitForm();
//...
splashScreenManager1.CloseWaitForm();

VB.NET

splashScreenManager1.ShowWaitForm()
'...
splashScreenManager1.CloseWaitForm()
  • 目標等待表單未激活。
DevExpress WinForms幫助文檔

要顯示/關閉等待表單,請使用靜態SplashScreenManager.ShowFormSplashScreenManager.CloseForm方法。 特定的SplashScreenManager.ShowForm方法重載允許您指定淡入淡出效果和等待表單位置。

C#

SplashScreenManager.ShowForm(typeof(WaitForm1));
//...
SplashScreenManager.CloseForm();

VB.NET

SplashScreenManager.ShowForm(GetType(WaitForm1))
'...
SplashScreenManager.CloseForm()

動態更新等待表單

與其他初始屏幕一樣,等待表單也顯示在單獨的線程中。

使用以下方法從主線程動態更新顯示等待表單的標題和描述:

您還可以使用SplashScreenManager.SendCommand方法與當前的等待表單進行交互(例如,更新其內容)。 要處理此方法發送的命令,請重寫WaitForm.ProcessCommand方法。

使用說明

顯示多個等待表單

如果您的應用程序一次只顯示一個等待表單,則可以使用單個SplashScreenManager組件。

若要同時顯示多個等待表單,請使用多個SplashScreenManager組件。

MDI應用

在MDI應用程序中,不要顯示Control.CreateHandle方法調用的事件或方法的等待表單 - HandleCreated,Load,MdiChildActivate,OnHandleCreated重載等,否則您的應用程序可能會凍結。

而是,使用以下方法:

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

上DevExpress中文網,獲取第一手最新產品資訊!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章