C # form gradient implementation

Source: Internet
Author: User
1 // after the program is opened, the form is gradually displayed from transparent to opaque.
2 // implementation method:
3. Add a Timer control (named fadeTimer in this example), and add the relevant code in FadeTimer_Tick to its Tick event.
4. Add the following code to the constructor of the Form class:
5 private bool showing = true;
6 public LoginForm ()
7 {
8 InitializeComponent ();
9
10 // form Display Effect
11 Opacity = 0.0; // the transparency of the form is 0.
12 fadeTimer. Start (); // Start time
13}
14
15 2. Tick event: Add the following control code:
16 private void FadeTimer_Tick (object sender, EventArgs e)
17 {
18 double d = 0.10;
19 if (showing)
20 {
21 if (Opacity + d >=1.0)
22 {
23 Opacity = 1.0;
24 fadeTimer. Stop ();
25}
26 else
27 {
28 Opacity + = d;
29}
30}
31 else
32 {
33 if (Opacity-d <= 0.0)
34 {
35 Opacity = 0.0;
36 fadeTimer. Stop ();
37} else
38 {
39 Opacity-= d;
40}
41}
42}

 

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.