Creating Spalsh Screen from an Image in C#
Hi I need to create a Splash Screen from an Image file. The Splash Screen form should be of the same dimensions as the image file. The program should hide the Splash Screen when my MainForm is displayed.
Here is what I'm doing
class SplashScreen : Form
{
Image splashImage;
public SplashScreen()
{
this.TopMost = true;
this.ShowInTaskbar = false;
this.FormBorderStyle = FormBorderStyle.None;
this.StartPosition = FormStartPosition.CenterScreen;
this.BackColor = this.TransparencyKey = Color.White;
Image img = Bitmap.FromFile("splash.png");
Bitmap b = new Bitmap(img);
b.MakeTransparent(b.GetPixel(1,1));
this.BackgroundImage = splashImage = (Image) b;
this.Size = this.splashImage.Size;
}
}
class MainForm : Form
{
public static void main(String[] args)
{
// Some Code
SplashScreen splash = new SplashScreen();
splash.Show();
MainForm mainForm = new MainForm();
mainForm.Shown += delegate(object o, EventArgs ev)
{
splash.Hide(); //Hide and Dispose the Splash Form When mainForm is shown for the first Time
splash.Dispose();
mainForm.GetFocus();
};
// More Code
}
}
The Splash Image to be used can be downloaded from
http://sukhjinder.cn/splash.pngWith the above code I do get the splash screen and the behaviour as expected but before the splash screen is drawn I see a Black Rectangle flashing, with same dimensions as the splash image.
Please suggest. If you have a different approach please go ahead. All I want is to see a nice Splash Screen
Thanks
Sukhjinder
http://sukhjinder.cn/