Click here to Skip to main content
12,760,662 members (32,316 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


6 bookmarked
Posted 12 Apr 2011

Make a WindowsForm fade in on form load and fade out on form close

, 12 Apr 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
using System;using System.Collections.Generic;using System.ComponentModel;using System.Text;using System.Windows.Forms;namespace FrmFadeApp{ public partial class FrmSplashScreen : Form { public frmSplashScreen() { InitializeComponent(); ...
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Windows.Forms;

namespace FrmFadeApp
    public partial class FrmSplashScreen : Form
        public frmSplashScreen()
      //Variable used to control whether form fade in or fade out 
        private bool Checkinout;
  //override the onload procedure of the from
     protected override void OnLoad(EventArgs e)
            if (!DesignMode)
                Checkinout = true;
                Opacity = 0;
                timer1.Enabled = true;
   /*DesignMode basically gets the value which indicates whether the   System.ComponentModel.Component is currently in design mode or not*/

// override the OnClosing procedure of the from
   protected override void OnClosing(CancelEventArgs e)
            if (e.Cancel == true)
            if (Opacity > 0)
                Checkinout = false;
                timer1.Enabled = true;
                e.Cancel = true;
//On timer1_Tick event use the Given Code 
  private void timer1_Tick(object sender, System.EventArgs e)
            if (Checkinout == false)
                Opacity -= (timer1.Interval / 1000.0);
                if (this.Opacity > 0)
                    timer1.Enabled = true;
                    timer1.Enabled = false;
                Opacity += (timer1.Interval / 1000.0);
                timer1.Enabled = (Opacity < 1.0);
                Checkinout = (Opacity < 1.0);

Now Run the Application you will see its FadeIn when Form loads and Fadeout when Form closing.


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


About the Author

Ravi Ranjan Kr
Software Developer
India India
Microsoft Student Partner | CS Student | MCTS | CP MVP | Crazy Learner | Dreamer

An Indian, who loves his country, believes in freedom, He is an enthusiast Techie and crazy learner. He is passionate about Technologies and social media. He holds bachelor degree of CS in Information Technology and now pursuing Master degree in Computer Application.

He always excited and keen Interested in learning and sharing knowledge. He loves to write blog, learn new things, listen music, taking arts and Playing Games..

He keep himself on the desk of his imagination, hanging around with some inceptions.

You may also be interested in...

Comments and Discussions

GeneralReason for my vote of 2 Code doesn't work. See alternate 2 Pin
Erion Pici19-Apr-11 0:09
memberErion Pici19-Apr-11 0:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170217.1 | Last Updated 12 Apr 2011
Article Copyright 2011 by Ravi Ranjan Kr
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid