Splash Screen Shows Black before Showing
-
I'm drawing a Splash Screen (Custom Shaped WinForm) as follows
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; this.BackgroundImage = splashImage = Bitmap.FromFile(SplashFileName); this.Size = this.BackgroundImage.Size; } protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); e.Graphics.DrawImage(this.splashImage, 0, 0, this.Width, this.Height); } }
and showing it in my Main method as
class MainForm : Form { public static void Main(String[] args) { //Do something here 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.Activate(); mainForm.Focus(); }; //Do something more here mainForm.Show(); Application.Run(mainForm); } }
Now the Issue is that the Splash Screen shows fine as per the Image from "SplashFileName" but just before showing it shows a Black Rectangle for some milliseconds. What I expect is that the Splash Screen be shown while my program is loading stuff and hide as soon as the MainForm gets Shown. So Where am I missing? Please Advice Thanks...
-
I'm drawing a Splash Screen (Custom Shaped WinForm) as follows
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; this.BackgroundImage = splashImage = Bitmap.FromFile(SplashFileName); this.Size = this.BackgroundImage.Size; } protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); e.Graphics.DrawImage(this.splashImage, 0, 0, this.Width, this.Height); } }
and showing it in my Main method as
class MainForm : Form { public static void Main(String[] args) { //Do something here 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.Activate(); mainForm.Focus(); }; //Do something more here mainForm.Show(); Application.Run(mainForm); } }
Now the Issue is that the Splash Screen shows fine as per the Image from "SplashFileName" but just before showing it shows a Black Rectangle for some milliseconds. What I expect is that the Splash Screen be shown while my program is loading stuff and hide as soon as the MainForm gets Shown. So Where am I missing? Please Advice Thanks...
Hi, as the splash image seems intended to fill the splash form, I see no reason to call base.OnPaint() so I suggest you take it out. :)
Luc Pattyn [Forum Guidelines] [My Articles]
Sorry for any delays in replying, I currently don't always get e-mail notifications.
-
Hi, as the splash image seems intended to fill the splash form, I see no reason to call base.OnPaint() so I suggest you take it out. :)
Luc Pattyn [Forum Guidelines] [My Articles]
Sorry for any delays in replying, I currently don't always get e-mail notifications.
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); e.Graphics.DrawImage(this.splashImage, 0, 0, this.Width, this.Height); }
I tried removing base.OnPaint(e) from above and removed the above method completly but still a get a Black Rectangle of the same Dimensions as my Splash Screen before I the latter becomes visible -
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); e.Graphics.DrawImage(this.splashImage, 0, 0, this.Width, this.Height); }
I tried removing base.OnPaint(e) from above and removed the above method completly but still a get a Black Rectangle of the same Dimensions as my Splash Screen before I the latter becomes visibleHi, I did some experiments, and it clearly is
this.TransparencyKey = Color.White;
that causes the initially black window. If you remove it, everything looks fine; if you need transparency, there might not be a solution (except maybe switching to WPF). :)Luc Pattyn [Forum Guidelines] [My Articles]
Sorry for any delays in replying, I currently don't always get e-mail notifications.
-
Hi, I did some experiments, and it clearly is
this.TransparencyKey = Color.White;
that causes the initially black window. If you remove it, everything looks fine; if you need transparency, there might not be a solution (except maybe switching to WPF). :)Luc Pattyn [Forum Guidelines] [My Articles]
Sorry for any delays in replying, I currently don't always get e-mail notifications.
Thanks for the reply. Yes taking out this.TransparencyKey = Color.White; does get rid of the Black Rectangle but my Image is not Rectangular. I know that we can draw Non-Rectangular WinForms using
this.BackColor = this.TransparencyKey = SomeColor; //Color.White in my case
In case you want to investigate further then my SplashForm Image is located at SplashScreen Image[^]