C # form gradient effect

Source: Internet
Author: User

After the program is opened, the form is gradually displayed from transparent to opaque.
Implementation Method:
1. Add a Timer control (named fadeTimer in this example), and then add the relevant code in FadeTimer_Tick to its Tick event. That's easy.
Add the following code to the constructor of the Form class:
1 private bool showing = true;
2 public LoginForm ()
3 {
4 InitializeComponent ();
5
6 // special form Display Effect
7 Opacity = 0.0; // the transparency of the form is 0.
8 fadeTimer. Start (); // Start time
9}

2. Tick event: Add the following control code:
1 private void FadeTimer_Tick (object sender, EventArgs e)
2 {
3 double d = 0.10;
4 if (showing)
5 {
6 if (Opacity + d >=1.0)
7 {
8 Opacity = 1.0;
9 fadeTimer. Stop ();
10}
11 else
12 {
13 Opacity + = d;
14}
15}
16 else
17 {
18 if (Opacity-d <= 0.0)
19 {
20 Opacity = 0.0;
21 fadeTimer. Stop ();
22} else
23 {
24 Opacity-= d;
25}
26}
27}

 

Author Cheng Yao

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.