Remove Flicker before drawing Splash Screen
-
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 File to be used is available here. With 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/ -
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 File to be used is available here. With 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/Sukhjinder_K wrote:
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;
I don't really get what you're trying to achieve here. Why not just use
this.BackColor = Color.Transparent;
this.BackgroundImage = Bitmap.FromFile"splash.png");If you include the tranparency in your image you should be pretty much done. If that doesn't work, you can always fill up the form with a PictureBox control. Oh, as for the flicer problem, try using
this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
on your form.Standards are great! Everybody should have one!
-
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 File to be used is available here. With 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/[DllImport("user32.dll")] public static extern bool LockWindowUpdate(IntPtr hWndLock); public SplashScreen() { this.TopMost = true; this.ShowInTaskbar = false; this.FormBorderStyle = FormBorderStyle.None; this.StartPosition = FormStartPosition.CenterScreen; Image img = Bitmap.FromFile(LetsYoConfig.SplashFileName); this.Size = img.Size; LockWindowUpdate(this.Handle); try { this.BackColor = this.TransparencyKey = Color.White; Bitmap b = new Bitmap(img); this.BackgroundImage = splashImage = (Image) b; } finally { LockWindowUpdate(IntPtr.Zero); } }