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 }