This post originated from an RSS feed registered with .NET Buzz
by Eric Gunnerson.
Original Post: Splash Screens and non-rectangular windows
Feed Title: Eric Gunnerson's C# Compendium
Feed URL: /msdnerror.htm?aspxerrorpath=/ericgu/Rss.aspx
Feed Description: Eric comments on C#, programming and dotnet in general, and the aerodynamic characteristics of the red-nosed flying squirrel of the Lesser Antilles
I needed a splash screen for my music player app. I tried a couple of ideas that didn't
work very well, but then I hit on the idea of using the image
of a CD as the background of the splash screen - and doing a non-rectangular window.
I'll start with the splash screen...
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();
splashForm.Show();
}
and we'll hook the Activated event to hide the form.
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.