Colorful effect-Fade-in and fade-out forms

Source: Internet
Author: User

Colorful effect-Fade-in and fade-out forms

In actual projects, forms are often popped up. To avoid being so abrupt, you can add excessive animation effects. Fade-in and fade-out is a common animation.

 1 using System; 2 using System.Windows.Forms; 3  4 namespace TestFormEffect 5 { 6     public partial class Form1 : Form 7     { 8         private readonly Timer _timer; 9         private readonly double _inspeed;10         private readonly double _outspeed;11 12         private State _state;13 14         public const float Precision = 0.000001f;15 16         public Form1()17         {18             InitializeComponent();19             _timer=new Timer();20             _timer.Tick += timer1_Tick; 21             _timer.Enabled = false;22 23             _inspeed = 20;24             _outspeed = 20;25         }26 27         private void Form1_Load(object sender, EventArgs e)28         {29             _state = State.In;30             _timer.Enabled = true;31             Opacity = 0;32         }33 34         private void timer1_Tick(object sender, EventArgs e)35         {36             switch (_state)37             {38                 case State.In:39                     Opacity += _inspeed/100;40                     if (1 - Opacity <= Precision)41                     {42                         _timer.Enabled = false;43                     }44                     break;45                 case State.Out:46                     Opacity -= _outspeed/100;47                     if (Opacity <= Precision)48                     {49                         this.Close();50                         _timer.Enabled = false;51                     }52                     break;53             }54         }55 56         private void Form1_FormClosing(object sender, FormClosingEventArgs e)57         {58             e.Cancel = true;59             _state = State.Out;60             _timer.Enabled = true;61         }62 63     }64 65     enum State66     {67         In=1,68         Out69     }70 }

 

  

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.