C # developing beautiful digital clocks,
Today, I made a beautiful digital clock with C. The interface is as follows.
Implementation Technology: The Graphics class DrawImage method is used to draw all the numbers in the digital clock. These numbers are some image files found online. The clock uses the Now attribute in DateTime to get different, hour, minute, second, and finally the timer to realize the running status of the clock.
Main Code:
[C-sharp]View plaincopy
- // Set 0 ~ 9. Save the digital Image to the Image array.
- Private Image [] image = new Bitmap [10];
- Public Form1 ()
- {
- InitializeComponent ();
- For (int I = 0; I <10; I ++)
- {
- Image [I] = new Bitmap (@ "D:/programming/C #/Digital Clock/Resources/" + I. ToString () + ". jpg ");
- }
- }
[C-sharp]View plaincopy
- Private void Form1_Paint (object sender, PaintEventArgs e)
- {
- Graphics g = e. Graphics;
- Int hh = DateTime. Now. Hour; // obtain the Hour number.
- Int hh1 = hh/10;
- Int hh2 = hh % 10;
- G. DrawImage (image [hh1], 20, 20, 80,180 );
- G. DrawImage (image [hh2], 100, 20, 80,180 );
- Int mm = DateTime. Now. Minute; // obtain the Minute number.
- Int mm1 = mm/10;
- Int mm2 = mm % 10;
- G. DrawImage (image [mm1], 260, 20, 80,180 );
- G. DrawImage (image [mm2], 340, 20, 80,180 );
- Int ss = DateTime. Now. Second; // obtain the Second number.
- Int ss1 = ss/10;
- Int ss2 = ss % 10;
- G. DrawImage (image [ss1], 500, 20, 80,180 );
- G. DrawImage (image [ss2], 580, 20, 80,180 );
- }
- Private void timereffectick (object sender, EventArgs e) // redraws the form.
- {
- This. Invalidate ();
- }
In addition, set the Interval attribute of Timer to 1000mm and Enable to True!
In the C language, what is the symbol (->) and how to use it?
This is a symbol in the struct pointer. Write a program to explain it, for example:
# Include <stdio. h>
Struct STU // define a struct
{
Int num;
} Stu;
Int main ()
{
Struct STU * p; // defines a struct pointer.
P = stu; // p points to the struct variable stu.
Stu. num = 100; // attaches an initial value to the struct member num.
Printf ("% d", p-> num); // output the num value in stu
Return;
}
As you can see, the-> method is to reference the variable in the struct !!
Format: p-> struct member (such as p-> num)
The function is equivalent to stu. num or (* p). num.
I don't know. You don't understand, and don't understand call me. O (∩ _ ∩) O ~
Hope to adopt it.
In the C language, what is the symbol (->) and how to use it?
This is a symbol in the struct pointer. Write a program to explain it, for example:
# Include <stdio. h>
Struct STU // define a struct
{
Int num;
} Stu;
Int main ()
{
Struct STU * p; // defines a struct pointer.
P = stu; // p points to the struct variable stu.
Stu. num = 100; // attaches an initial value to the struct member num.
Printf ("% d", p-> num); // output the num value in stu
Return;
}
As you can see, the-> method is to reference the variable in the struct !!
Format: p-> struct member (such as p-> num)
The function is equivalent to stu. num or (* p). num.
I don't know. You don't understand, and don't understand call me. O (∩ _ ∩) O ~
Hope to adopt it.