Splash Screens and non-rectangular windows

While searching, I found a very interesting article in a blog. It was about to create a splash screen. This article is extracted from that site. Check out for the link of the blog at the end of the article.

Conceptually, a splash screen is pretty simple – it’s just a form that you bring up at the start of the program. The code is something like this:

SplashForm splashForm;
public MyForm()
    splashForm = new SplashForm();

and we’ll hook the Activated event to hide the form.

private void Form1_Activated(object sender, System.EventArgs e){

When we run this, however, something strange happens. The form comes up, but it never renders – there’s just a black background. This is because we need the windows messages to be processed to get the form to paint. There are several ways to do this, but my choice is to simply call Application.DoEvents() after the form is shown. This processes any messages that have yet to be processed, showing the form.Next, we need to make a non-rectangular form. This is done by setting the region on the form. This is surprisingly easy to do. Here’s the code I used for the CD:

public SplashForm()
    GraphicsPath p = new GraphicsPath();
    p.AddEllipse(2, 4, 340, 341);
    p.AddEllipse(150, 153, 43, 43);
    this.Region = new Region(p);


The first ellipse defines the outside of the picture, and then the second one this inside. This gives me a round window with a hole in the center.

Pretty cool!

Article Link: http://blogs.msdn.com/ericgu/archive/2003/09/24/52645.aspx


One thought on “Splash Screens and non-rectangular windows

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s