Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Splash Screen Shows Black before Showing

Splash Screen Shows Black before Showing

Scheduled Pinned Locked Moved C#
graphicshelpquestion
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Sukhjinder_K
    wrote on last edited by
    #1

    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...

    L 1 Reply Last reply
    0
    • S Sukhjinder_K

      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...

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      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.


      S 1 Reply Last reply
      0
      • L Luc Pattyn

        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.


        S Offline
        S Offline
        Sukhjinder_K
        wrote on last edited by
        #3

        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

        L 1 Reply Last reply
        0
        • S Sukhjinder_K

          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

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          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.


          S 1 Reply Last reply
          0
          • L Luc Pattyn

            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.


            S Offline
            S Offline
            Sukhjinder_K
            wrote on last edited by
            #5

            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[^]

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups