Splash window is a fancy feature and many applications have it. In Revit addins, it may also be necessary to display a splash window sometimes.
Here is a simple and functional splash window sample in VB.NET:
Imports System.Windows.Forms
Imports System.Drawing
Public Class SplashWindow
Private form As Form = Nothing
Private timer As Timer = Nothing
Public Sub New(ByVal width As Integer, ByVal height As Integer, ByVal interval_milisecs As Integer, ByVal image As Image)
form = New Form()
form.Width = width
form.Height = height
form.BackgroundImage = image
form.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch
form.StartPosition = FormStartPosition.CenterScreen
form.FormBorderStyle = FormBorderStyle.None
form.TopMost = True
timer = New Timer()
timer.Interval = interval_milisecs
AddHandler timer.Tick, New EventHandler(AddressOf timer_Tick)
timer.Start()
form.Show()
End Sub
Private Sub timer_Tick(ByVal sender As Object, ByVal args As EventArgs)
timer.Stop()
form.Close()
End Sub
End Class
The splash window displays a background image and its width, height and the display time can be specified.
As can be noticed, a windows Form and a Timer are used in the splash window class. The Form is to display the image and the Timer is to control its life time.
To use the splash window is also very easy, creating an instance of the SplashWindow class in the OnStartup of an external application and providing proper values for the width, height and time and feeding a good image to the constructor:
Public Function OnStartup(ByVal uiApp As UIControlledApplication) As Result Implements IExternalApplication.OnStartup
_cachedUiCtrApp = uiApp
Try
Dim ribbonPanel As RibbonPanel = CreateRibbonPanel()
''TODO: add you code below.
Dim sw As New SplashWindow(300, 300, 30000, New System.Drawing.Bitmap("c:/temp/SplashWindow1.bmp"))
Return Result.Succeeded
Catch ex As Exception
MessageBox.Show(ex.ToString())
Return Result.Failed
End Try
End Function
That is about it!
RevitAddinWizard provide a Coder for the SplashWindow creation in both C# and VB.NET.
Recent Comments