Click here to Skip to main content
12,820,289 members (31,086 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

Software Developer
India India
Microsoft Student Partner | MCTS | CP MVP | Crazy Learner

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

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

You may also be interested in...

Comments and Discussions

GeneralRe: Code doesn't work. I'm submitting an alternative. Pin
Erion Pici19-Apr-11 0:00
memberErion Pici19-Apr-11 0:00 
GeneralRe: I used it and it work just fine, thank you! Pin
mehran_o_net18-Apr-11 23:50
membermehran_o_net18-Apr-11 23:50 
Generalyea same problem i ran into thats why i posted above. What s... Pin
charles henington19-Apr-11 12:30
membercharles henington19-Apr-11 12:30 
GeneralReason for my vote of 4 It's a good alternate. In fact the c... Pin
Thiago Marçal19-Apr-11 8:42
memberThiago Marçal19-Apr-11 8:42 
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 
GeneralReason for my vote of 1 reason stated above Pin
charles henington14-Apr-11 5:00
membercharles henington14-Apr-11 5:00 
GeneralRe: Check my reply which is too stated above. Pin
RaviRanjankr14-Apr-11 6:25
mvpRaviRanjankr14-Apr-11 6:25 
Generalwhy would you base the opacity on the timer1.Interval? thats... Pin
charles henington12-Apr-11 17:06
membercharles henington12-Apr-11 17:06 
GeneralRe: Its run properly even doing fade in or Fadeout too. and its ... Pin
RaviRanjankr14-Apr-11 6:24
mvpRaviRanjankr14-Apr-11 6:24 
Its run properly even doing fade in or Fadeout too. and its too visible when I run the Application.
I Will sure do work with bugs but it should be occurred Smile | :)

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.170308.1 | Last Updated 12 Apr 2011
Article Copyright 2011 by RaviRanjanKr
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid