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:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
namespace Tools
{
public class SplashWindow
{
private Form form = null;
private Timer timer = null;
public SplashWindow(int width, int height, int interval_milisecs, Image image)
{
form = new Form();
form.Width = width;
form.Height = height;
form.BackgroundImage = image;
form.BackgroundImageLayout = ImageLayout.Stretch;
form.StartPosition = FormStartPosition.CenterScreen;
form.FormBorderStyle = FormBorderStyle.None;
form.TopMost = true;
timer = new Timer();
timer.Interval = interval_milisecs;
timer.Tick += new EventHandler(timer_Tick);
timer.Start();
form.Show();
}
private void timer_Tick(object sender, EventArgs args)
{
timer.Stop();
form.Close();
}
}
}
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 Result OnStartup(UIControlledApplication uiApp)
{
_cachedUiCtrApp = uiApp;
try
{
RibbonPanel ribbonPanel = CreateRibbonPanel();
//TODO: add you code below.
new SplashWindow(600, 300, 10000, new Bitmap(@"c:\temp\splash.bmp"));
return Result.Succeeded;
}
catch (Exception ex)
{
MessageBox.Show( ex.ToString() );
return Result.Failed;
}
}
That is about it!
RevitAddinWizard provides a Coder for the SplashWindow creation.
Recent Comments