This article describes how to implement a small clock program.
The Figure 2 shows the execution result of the program example. in the form Load event processing routine, the radius and coordinates of the drawn clock are calculated. when the user adjusts the window size of the clock, the form automatically redraws the content of the clock in double buffer control mode. The reason why double buffering is set is to reduce the screen flashing caused by the screen weight painting, the program code is listed below:
Private void Blog_DemoForm007_Load (object sender, EventArgs e) {// Determine whether the frame style of the form is adjustable. DoShowFrame = (this. FormBorderStyle = FormBorderStyle. Sizable); DemoClock = new Clock (this); // Retrieve the coordinates of the width and height of the rectangle. ClientOffset = CalcClientLocation (); // calculates the clock radius and coordinates. CalcCircleSize (); // specifies the form style bit. when the widget is adjusted for an hour, it is re-drawn. This. setStyle (ControlStyles. resizeRedraw, true); // specifies the form style bit. the control ignores the window message WM_ERASEBKGND to reduce the re-painting and flashing. // The control is drawn by itself and does not need to be executed by the operating system, // and the painting has been executed in the buffer zone. after the painting is complete, the result is output to the screen. // you can set the double buffer to avoid the re-painting and flashing caused by the re-painting of the control. This. SetStyle (ControlStyles. AllPaintingInWmPaint | ControlStyles. UserPaint | ControlStyles. DoubleBuffer, true );}
In addition to changing the size of the form, the user can also make the form frame of the peripheral clock disappear, so that the appearance of the small clock is no different from that of the traditional clock, as shown in Table 3:
You may ask, can you drag a small clock to the desired position without an external frame? The answer is yes. Write the following program code in the MouseDown, MouseUp, and MouseMove event processing routines of the form:
Private void Blog_DemoForm007_MouseDown (object sender, MouseEventArgs e) {// the user presses the left mouse button. If (e. button = MouseButtons. left) {IsMouseDown = true; MouseOffset. X = e. x; MouseOffset. Y = e. Y ;}} private void Blog_DemoForm007_MouseUp (object sender, MouseEventArgs e) {IsMouseDown = false;} private void Blog_DemoForm007_MouseMove (object sender, MouseEventArgs e) {// Move the form position. If (IsMouseDown) {this. location = new Point (this. location. X + e. x-MouseOffset. x, this. location. Y + e. y-MouseOffset. Y );}}
Soon, we will complete a more complete small clock example and add more and more functions, such: countdown, changing the color and progressive effect of the clock, displaying the text clock, and setting the clock function file. let's talk about it today and see you next time.
The above is a detailed description of the implementation method of the small clock program. For more details, please follow other related articles in the first PHP community!