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