Welcome to MSDN Blogs Sign in | Join | Help

Splash Screens and non-rectangular windows

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.

private void Form1_Activated(object sender, System.EventArgs e)
{
    splashForm.Close();
}

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!

Published Wednesday, September 24, 2003 11:53 PM by ericgu
Filed under: ,

Comments

Thursday, September 25, 2003 9:27 AM by Jacob

# RE: Splash Screens and non-rectangular windows

I use a slightly different approach for my splash screens, but I think the end result is the same: Public Class ApplicationEntryPoint Private Shared m_splash As SplashScreen Private Shared m_context As ApplicationContext Private Sub New() End Sub <STAThread()> _ Public Shared Sub Main(ByVal CmdArgs() As String) m_context = New ApplicationContext() If CmdArgs.Length > 0 AndAlso CmdArgs(0) = "/NoSplash" Then m_context.MainForm = New MainForm() Else AddHandler Application.Idle, AddressOf AppIdle m_splash = New SplashScreen() m_splash.TopMost = True m_splash.Show() End If Application.Run(m_context) End Sub Private Shared Sub AppIdle(ByVal sender As Object, ByVal e As EventArgs) If m_context.MainForm Is Nothing Then RemoveHandler Application.Idle, AddressOf AppIdle m_context.MainForm = New MainForm() m_context.MainForm.Show() m_splash.Close() m_splash = Nothing End If End Sub End Class
Friday, September 26, 2003 6:33 PM by Darren Neimke

# RE: Splash Screens and non-rectangular windows

Thanks Eric!
Monday, June 21, 2004 3:48 AM by Irfan Patel (MCSD)

# I chose a recommended way..

Nice code for the non-rectangular way but I created a new class for splash screen and frmMain in C#.
There is a timer set in frmSplash whose tick event has databaseconnection code and this.Close(); to close the frmSplash
:) The additional class is as follows


using System;
using System.Windows.Forms;
namespace MyNamespace.Classes
{
/// <summary>
/// Summary description for clsMain.
/// </summary>
public class clsMain
{
public clsMain()
{
}
[STAThread]
static void Main()
{
frmSplash objfrmSplash = new frmSplash();
objfrmSplash.ShowDialog();

clsGlobal.g_objfrmMain = new frmMain();
//clsGlobal.g_objfrmMain.Show();

Application.Run(clsGlobal.g_objfrmMain);

}
}
}


Have a nice time :)
patelirfan786@yahoo.com
Saturday, December 18, 2004 10:52 AM by MBA

# MBA

Helpful For MBA Fans.
Sunday, October 22, 2006 1:42 PM by .Avery Blog

# Splash Screens in Windows Forms

Splash Screens in Windows Forms

Monday, October 23, 2006 12:47 AM by Nick Randolph's .NET Travels

# Splash screens using VB2005 Application Framework

James Avery makes a point that Eric Gunnerson has a way of doing splash screens. Unfortunately...

# Splash Screens and non-rectangular windows &laquo; Vakul Kumar More

New Comments to this post are disabled
 
Page view tracker