啟動(dòng)圖像
啟動(dòng)畫面管理器允許您將任何圖像顯示為啟動(dòng)畫面。

主要功能包括:
- 支持圖像透明性,因此初始圖像可能是不規(guī)則的形式,并且可能包含陰影。
- 支持設(shè)計(jì)時(shí)自定義。
- 可以在主表單啟動(dòng)時(shí)自動(dòng)顯示和關(guān)閉。
- 允許您自定義繪制圖像。
- 通過命令與啟動(dòng)表單進(jìn)行交互。
用代碼創(chuàng)建和顯示啟動(dòng)圖像
這種方法使您可以用一行代碼將任何圖像顯示為啟動(dòng)圖像,您可以使用自定義的繪圖器繪制啟動(dòng)圖像(例如,繪制進(jìn)度指示器)。
要調(diào)用啟動(dòng)圖像,請(qǐng)調(diào)用靜態(tài)SplashScreenManager.ShowImage方法,將目標(biāo)圖像指定為參數(shù)。 若要隱藏圖像,請(qǐng)調(diào)用靜態(tài)SplashScreenManager.HideImage方法。
C# :
Image im = Image.FromFile("mySplashScreen.png"); SplashScreenManager.ShowImage(im); //... SplashScreenManager.HideImage();
VB.NET :
Dim im As Image = Image.FromFile("mySplashScreen.png") SplashScreenManager.ShowImage(im) '... SplashScreenManager.HideImage()
SplashScreenManager.ShowImage方法重載允許您指定圖像位置并啟用淡入淡出動(dòng)畫效果。
自定義繪制啟動(dòng)圖像
要顯示啟動(dòng)圖像并在初始圖像上繪制圖形,請(qǐng)執(zhí)行以下操作:
- 創(chuàng)建一個(gè)支持ICustomImagePainter接口的類。
- 通過ICustomImagePainter.Draw方法實(shí)現(xiàn)繪制過程。
- 將ShowImage方法重載與'painter'參數(shù)一起使用,并傳遞ICustomImagePainter對(duì)象作為此參數(shù)。
每次顯示圖像時(shí),都會(huì)調(diào)用ICustomImagePainter.Draw方法。 要強(qiáng)制更新初始圖像,請(qǐng)調(diào)用SplashScreenManager.Invalidate方法。
在設(shè)計(jì)時(shí)創(chuàng)建啟動(dòng)圖像(手動(dòng)或自動(dòng)顯示)
此方法提供以下自定義選項(xiàng):
- 允許您在設(shè)計(jì)時(shí)創(chuàng)建啟動(dòng)圖像。
- 在主表單啟動(dòng)時(shí)自動(dòng)顯示和關(guān)閉啟動(dòng)圖像。
- 顯示并關(guān)閉代碼中的啟動(dòng)圖像。
- 在啟動(dòng)畫面上添加自定義控件。
- 訪問并擴(kuò)展初始圖像類的實(shí)現(xiàn)。
- 使用命令與代碼中的初始圖像進(jìn)行交互。
創(chuàng)建啟動(dòng)圖像
- 右鍵單擊Visual Studio tray中的SplashScreenManager組件,然后選擇Add Splash Screen。

- 在Solution Explorer中雙擊生成的SplashScreen1.cs(SplashScreen1.vb)文件來打開設(shè)計(jì)時(shí)編輯器。

- 將SplashScreen的ShowMode屬性設(shè)置為Image。

- 您也可以使用 SplashScreen.SplashImageOptions 屬性來指定自定義圖像。

添加對(duì)圖像的自定義控件
在圖像上方顯示自定義控件:
- 啟用SplashScreen.AllowControlsInImageMode選項(xiàng)。
- 將自定義控件添加到啟動(dòng)畫面。
注意:如果您需要使用自定義類擴(kuò)展SplashScreen1.cs/.vb文件,請(qǐng)確保封裝Splash Screen的類在這些文件中排在第一位。
啟動(dòng)時(shí)自動(dòng)顯示和關(guān)閉
要在主表單的啟動(dòng)時(shí)自動(dòng)顯示創(chuàng)建的Splash Image,請(qǐng)確保將SplashScreenManager的Active Splash Form設(shè)置為您的啟動(dòng)畫面, 打開SplashScreenManager的智能標(biāo)記,然后檢查“ Active Splash Form”設(shè)置。

- 或者,您可以檢查屬性網(wǎng)格中的SplashScreenManager.ActiveSplashFormTypeInfo 設(shè)置。

啟動(dòng)畫面管理器會(huì)在主窗體啟動(dòng)時(shí)自動(dòng)顯示激活的啟動(dòng)畫面,并在初始化和顯示主表單時(shí)將其關(guān)閉。
手動(dòng)顯示和關(guān)閉
確保啟動(dòng)畫面管理器的Active Splash Form設(shè)置為 '(None)'。

若要顯示和關(guān)閉創(chuàng)建的啟動(dòng)畫面,請(qǐng)使用靜態(tài)SplashScreenManager.ShowForm和SplashScreenManager.CloseForm方法。
C# :
SplashScreenManager.ShowForm(typeof(SplashScreen1)); //... SplashScreenManager.CloseForm();
VB.NET :
SplashScreenManager.ShowForm(GetType(SplashScreen1)) '... SplashScreenManager.CloseForm()
動(dòng)態(tài)更新啟動(dòng)畫面
啟動(dòng)畫面顯示在單獨(dú)的線程中。 在代碼中,您可以通過SplashScreenManager.SendCommand 方法發(fā)送的命令與激活的啟動(dòng)畫面進(jìn)行交互(例如,動(dòng)態(tài)更新自定義控件)。若要處理這些命令,請(qǐng)重寫SplashScreen.ProcessCommand 方法。