Click here to Skip to main content
6,634,665 members and growing! (15,358 online)
Email Password   helpLost your password?
Languages » C# » Windows Forms     Beginner License: The Code Project Open License (CPOL)

Using Form Opacity to Make Splash Screen for your Project (Fade In & Fade Out)

By Rin Reaksmey

Make Fade In & Fade Out animation with Windows Form using C#
C#WinXP, Win2003, Vista, .NET 3.0, .NET 3.5VS2008
Posted:2 Sep 2008
Views:7,797
Bookmarked:17 times
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
6 votes for this article.
Popularity: 2.82 Rating: 3.63 out of 5

1
1 vote, 16.7%
2
1 vote, 16.7%
3
2 votes, 33.3%
4
2 votes, 33.3%
5

Introduction

Hello! This is my first article on The Code Project and I hope this will give you some opinion of creating a splash screen for your application using the form opacity property.

NOTE: I created this project with Visual Studio 2008 and .NET Framework 3.5, so you MUST use Visual Studio 2008 to open the project otherwise it will not work. You could just open the source code file (*.cs) to browse the code. Thanks.

Using the Code

The main idea of this project is to make Fade In and Fade Out animation with the Windows Form. The main component of this project is System.Windows.Forms.Timer.

In the project, I have two Timer Controls, one which is used for Fade In effect and the other for Fade Out effect.

Make the form invisible when the form loads, then start the Fade In effect by enabling the timerFadeIn control...

private void Form1_Load(object sender, EventArgs e)
{
	this.Opacity = 0;
	timerFadeIn.Enabled = true;//Enable the timerFadeIn to start Fade In Effect
	timerFadeOut.Enabled = false;
}

Next, the code in timerFadeIn_Tick event:

private void timerFadeIn_Tick(object sender, EventArgs e)
{//Fade in effect
            i += 0.05;
            if (i >= 1)
            {//if form is fully visible, we execute the Fade Out Effect
                this.Opacity = 1;
                timerFadeIn.Enabled = false;//stop the Fade In Effect
                timerFadeOut.Enabled = true;//start the Fade Out Effect
                return;
            }
            this.Opacity = i;
}

Finally, after the form is fully visible, we make the Fade Out effect in the timerFadeOut_Tick event.

private void timerFadeOut_Tick(object sender, EventArgs e)
{//Fade out effect
            i -= 0.05;
            if (i <= 0.01)
            {//if form is invisible, we execute the Fade In Effect again
                this.Opacity = 0.0;
                timerFadeIn.Enabled = true;//start the Fade In Effect
                timerFadeOut.Enabled = false;//stop the Fade Out Effect
                return;
            }
            this.Opacity = i;
}

Points of Interest

I have a lot of fun working with this project and I hope it will come handy for you and hope you will have fun like me too. Comments and advice will be gladly appreciated, thanks.

Related Topic

You can check Mr. Mohammad Dayyan's article about form opacity here for more resources and code.

History

  • 2nd September, 2008: Initial post

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Rin Reaksmey


Member

Occupation: Software Developer
Company: Safety-Cam
Location: Cambodia Cambodia

Other popular C# articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
  (Refresh) 
-- There are no messages in this forum --

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 2 Sep 2008
Editor: Deeksha Shenoy
Copyright 2008 by Rin Reaksmey
Everything else Copyright © CodeProject, 1999-2009
Web10 | Advertise on the Code Project