A small C # form program

Source: Internet
Author: User

ThisProgramThis is an excerpt from head first in C #, Which is photocopied by Southeast University Press.

This program has many key points.

1. application. doevents () // used to view the gradient process of the program

2. While (visible) // to make the background color gradient before the program is closed

3. system. Threading. thread. Sleep (10) // the program will be suspended after 10 seconds.

ProcedureCodeAs follows:
This form has only one button control. The following code and interpretation of the code used to trigger the function by using the click () event of the button are as follows:Source codeOnly the code in the click () event is copied:

 

Button_click ()

  1     Private    Void  Button#click (  Object  Sender, eventargs E)
2 {
3 While (Visible)
4 { /* While (visible) in order to keep the color gradient before the program is not closed, highlight the loop when it is closed */
5
6 /* In the for statement, C <254 & visible is used to determine to exit the loop when the program is closed. Otherwise, the program will be launched in a delayed manner, because when the program is closed,
7 While (visible) is still detected, the for statement is still being executed and will not return to the edit interface until the two for loop ends. */
8 For ( Int C = 0 ; C < 254 && Visible; c ++ )
9 {
10 This . Backcolor = Color. fromargb (C, 255 - C, C );
11 Application. doevents (); // If this sentence does not exist, the program cannot be executed normally. No response is returned when you click (X ).
12 // This thread is suspended after 10 s
13   System. Threading. thread. Sleep ( 10 ); // This slows down the color of the northern background for easy observation. The entire gradient process is ordered for 10 seconds.
14  
15 }
16 For ( Int C = 254 && Visible; c > = 0 ; C -- ) // Returns the initial color.
17   {
18 This . Backcolor = Color. fromargb (C, 255 - C, C );
19 Application. doevents ();
20 System. Threading. thread. Sleep ( 10 );
21 }
22 }
23 }

 

 

 

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.