Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.
How to: Show an Image as a Splash Screen and Draw Custom Information Over this Image
6 minutes to read
In this example, an image is displayed as a splash screen via the SplashScreenManager.ShowImage method.Custom information is painted over this image via a custom class (SplashImagePainter), whose instance is passed as a parameter to the ShowImage method. The SplashImagePainter draws text labels with custom progress information.
usingSystem;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Windows.Forms;
usingDevExpress.XtraSplashScreen;
namespaceSplashScreenManagerSample01 {
publicpartialclassForm1 : Form {
publicForm1() {
InitializeComponent();
LongInitialization();
}
protectedvoidLongInitialization() {
BaseInitialization();
LoadFonts();
LoadTextures();
}
voidBaseInitialization() {
// Set progress stage to be displayed by SplashImagePainter
SplashImagePainter.Painter.ViewInfo.Stage = "Initialization";
for(int i = 1; i <= 100; i++) {
System.Threading.Thread.Sleep(20);
// Change progress to be displayed by SplashImagePainter
SplashImagePainter.Painter.ViewInfo.Counter = i;
//Force SplashImagePainter to repaint information
SplashScreenManager.Default.Invalidate();
}
}
voidLoadFonts() {
// Set progress stage to be displayed by SplashImagePainter
SplashImagePainter.Painter.ViewInfo.Stage = "Loading Fonts";
for(int i = 1; i <= 100; i++) {
System.Threading.Thread.Sleep(20);
// Change progress to be displayed by SplashImagePainter
SplashImagePainter.Painter.ViewInfo.Counter = i;
//Force SplashImagePainter to repaint information
SplashScreenManager.Default.Invalidate();
}
}
voidLoadTextures() {
// Set progress stage to be displayed by SplashImagePainter
SplashImagePainter.Painter.ViewInfo.Stage = "Loading Textures";
for(int i = 1; i <= 100; i++) {
System.Threading.Thread.Sleep(20);
// Change progress to be displayed by SplashImagePainter
SplashImagePainter.Painter.ViewInfo.Counter = i;
//Force SplashImagePainter to repaint information
SplashScreenManager.Default.Invalidate();
}
}
//protectedoverridevoidOnLoad(EventArgs e) {
base.OnLoad(e);
// Close splash image
SplashScreenManager.HideImage();
}
}
}
ImportsMicrosoft.VisualBasicImportsSystemImportsSystem.DrawingImportsSystem.ReflectionImportsSystem.Windows.FormsImportsDevExpress.XtraSplashScreenNamespace SplashScreenManagerSample01
FriendNotInheritableClass Program
PrivateSubNew()
EndSub
<STAThread> _
SharedSub Main()
Application.EnableVisualStyles()
Application.SetCompatibleTextRenderingDefault(False)
Dim image As Image = GetImage()
' Show splash image
SplashScreenManager.ShowImage(image, True, True, SplashImagePainter.Painter)
Application.Run(New Form1())
EndSubPrivateSharedFunction GetImage() As Image
Dim asm As System.Reflection.Assembly = GetType(Program).AssemblyReturnNew Bitmap(asm.GetManifestResourceStream("DefSplashImage.png"))
EndFunctionEndClassEndNamespace
ImportsMicrosoft.VisualBasicImportsSystemImportsSystem.Collections.GenericImportsSystem.ComponentModelImportsSystem.DataImportsSystem.DrawingImportsSystem.LinqImports System.TextImportsSystem.Windows.FormsImportsDevExpress.XtraSplashScreenNamespace SplashScreenManagerSample01
PartialPublicClass Form1
Inherits Form
PublicSubNew()
InitializeComponent()
LongInitialization()
EndSubProtectedSub LongInitialization()
BaseInitialization()
LoadFonts()
LoadTextures()
EndSubPrivateSub BaseInitialization()
' Set progress stage to be displayed by SplashImagePainter
SplashImagePainter.Painter.ViewInfo.Stage = "Initialization"For i AsInteger = 1To100
System.Threading.Thread.Sleep(20)
' Change progress to be displayed by SplashImagePainter
SplashImagePainter.Painter.ViewInfo.Counter = i
'Force SplashImagePainter to repaint information
SplashScreenManager.Default.Invalidate()
Next i
EndSubPrivateSub LoadFonts()
' Set progress stage to be displayed by SplashImagePainter
SplashImagePainter.Painter.ViewInfo.Stage = "Loading Fonts"For i AsInteger = 1To100
System.Threading.Thread.Sleep(20)
' Change progress to be displayed by SplashImagePainter
SplashImagePainter.Painter.ViewInfo.Counter = i
'Force SplashImagePainter to repaint information
SplashScreenManager.Default.Invalidate()
Next i
EndSubPrivateSub LoadTextures()
' Set progress stage to be displayed by SplashImagePainter
SplashImagePainter.Painter.ViewInfo.Stage = "Loading Textures"For i AsInteger = 1To100
System.Threading.Thread.Sleep(20)
' Change progress to be displayed by SplashImagePainter
SplashImagePainter.Painter.ViewInfo.Counter = i
'Force SplashImagePainter to repaint information
SplashScreenManager.Default.Invalidate()
Next i
EndSub'ProtectedOverridesSub OnLoad(ByVal e As EventArgs)
MyBase.OnLoad(e)
' Close splash image
SplashScreenManager.HideImage()
EndSubEndClassEndNamespace
ImportsMicrosoft.VisualBasicImportsSystem.DrawingImportsDevExpress.Utils.DrawingImports DevExpress.Utils.TextImportsDevExpress.XtraSplashScreenNamespace SplashScreenManagerSample01
FriendClass SplashImagePainter
Implements ICustomImagePainter
SharedSubNew()
Painter = New SplashImagePainter()
EndSubProtectedSubNew()
EndSubPrivateShared privatePainter As SplashImagePainter
PublicSharedProperty Painter() As SplashImagePainter
GetReturn privatePainter
EndGetPrivateSet(ByVal value As SplashImagePainter)
privatePainter = value
EndSetEndPropertyPrivate info As ViewInfo = NothingPublicReadOnlyProperty ViewInfo() As ViewInfo
GetIfMe.info IsNothingThenMe.info = New ViewInfo()
EndIfReturnMe.info
EndGetEndProperty#Region "Drawing"PublicSub Draw(ByVal cache As GraphicsCache, ByVal bounds As Rectangle) Implements ICustomImagePainter.Draw
Dim pt As PointF = ViewInfo.CalcProgressLabelPoint(cache, bounds)
cache.Graphics.DrawString(ViewInfo.Text, ViewInfo.ProgressLabelFont, ViewInfo.Brush, pt)
EndSub#EndRegionEndClassFriendClass ViewInfo
PublicSubNew()
Counter = 1
Stage = String.Empty
EndSubPrivate privateCounter AsIntegerPublicProperty Counter() AsIntegerGetReturn privateCounter
EndGetSet(ByVal value AsInteger)
privateCounter = value
EndSetEndPropertyPrivate privateStage AsStringPublicProperty Stage() AsStringGetReturn privateStage
EndGetSet(ByVal value AsString)
privateStage = value
EndSetEndPropertyPublicFunction CalcProgressLabelPoint(ByVal cache As GraphicsCache, ByVal bounds As Rectangle) As PointF
Const yOffset AsInteger = 40Dim size As Size = TextUtils.GetStringSize(cache.Graphics, Text, ProgressLabelFont)
ReturnNew Point(bounds.Width / 2 - size.Width / 2, yOffset)
EndFunctionPrivate progressFont As Font = NothingPublicReadOnlyProperty ProgressLabelFont() As Font
GetIfMe.progressFont IsNothingThenMe.progressFont = New Font("Consolas", 10)
EndIfReturnMe.progressFont
EndGetEndPropertyPrivate brush_Renamed As Brush = NothingPublicReadOnlyProperty Brush() As Brush
GetIfMe.brush_Renamed IsNothingThenMe.brush_Renamed = New SolidBrush(Color.Black)
EndIfReturnMe.brush_Renamed
EndGetEndPropertyPublicReadOnlyPropertyText() AsStringGetReturnString.Format("{0} - ({1}%)", Stage, Counter.ToString("D2"))
EndGetEndPropertyEndClassEndNamespace
Was this page helpful?
Thanks for your feedback!
How can we improve this help topic?
Additional comments/thoughts:
If you have any questions, submit a ticket to our Support Center.