Click here to Skip to main content
15,886,026 members
Articles / Multimedia / GDI+

Fading Forms In and Out

Rate me:
Please Sign up or sign in to vote.
4.17/5 (15 votes)
13 Aug 2007CPOL2 min read 106.8K   1.3K   85  
Add fade transitions to your applications
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace FadeForm
{
    public partial class FadeFormDemo : FadeForm
    {
        public FadeFormDemo()
        {
            InitializeComponent();
            numericUpDownMinimizedOpacity.Value = (decimal)this.MinimizedOpacity;
            numericUpDownActiveOpacity.Value = (decimal)this.ActiveOpacity;
            numericUpDownInactiveOpacity.Value = (decimal)this.InactiveOpacity;
            numericUpDownTargetOpacity.Value = (decimal)this.TargetOpacity;
            numericUpDownFadeTime.Value = (decimal)this.FadeTime;
            timer1.Start();
        }

        [STAThread]
        static void Main()
        {
            Application.Run(new FadeFormDemo());
        }

        private void numericUpDownMinimizedOpacity_ValueChanged(object sender, EventArgs e)
        {
            this.MinimizedOpacity = (double)numericUpDownMinimizedOpacity.Value;
        }

        private void numericUpDownActiveOpacity_ValueChanged(object sender, EventArgs e)
        {
            this.ActiveOpacity = (double)numericUpDownActiveOpacity.Value;
        }

        private void numericUpDownInactiveOpacity_ValueChanged(object sender, EventArgs e)
        {
            this.InactiveOpacity = (double)numericUpDownInactiveOpacity.Value;
        }

        private void numericUpDownFadeTime_ValueChanged(object sender, EventArgs e)
        {
            this.FadeTime = (double)numericUpDownFadeTime.Value;
        }

        private void buttonTargetOpacity_Click(object sender, EventArgs e)
        {
            this.TargetOpacity = (double)numericUpDownTargetOpacity.Value;
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if(!numericUpDownTargetOpacity.Focused&&!buttonTargetOpacity.Focused)numericUpDownTargetOpacity.Value=(decimal)this.TargetOpacity;
        }

        private void FadeFormDemo_Activated(object sender, EventArgs e)
        {
            numericUpDownMinimizedOpacity.Focus();
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

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


Written By
Instructor / Trainer
United States United States
I am a mechanical engineer that works as a high school math teacher in Mulberry, Arkansas. I use programming as one way to keep my mind sharp.

Comments and Discussions