Home > Back-end >  How to use C Builder to complete the realization of the clock
How to use C Builder to complete the realization of the clock

Time:10-14

I am a novice, want to ask how the clock to implement in c + + builder, requires a dynamic form of image, hurry to overcome!

CodePudding user response:

To drag a timer to form, set up the event interval is 1000 (1 second), and then draw clockwise in the OnTimer event, minute hand and second hand, first with the background color of a second before the clock pointer to draw again, to erase a second image, and then use the color of the actual drawing a second clock pointer

CodePudding user response:

There are instances, their search,

CodePudding user response:

 
Void__fastcall TForm1: : FormPaint (TObject * Sender)
{
Float deg.
Int x1, y1, x2, y2;
Canvas - & gt; Pen - & gt; Width=5;
for (int i=0; i<12. I++)
//this cycle in uniform distribution on the circumference of a circle of 12 short
{
Deg=I * 3.1416/6;
//define a point of view, in arc unit said
X1=100 * cos (deg);
Y1=100 * sin (deg);
X2=120 * cos (deg);
Y2=120 * sin (deg);//determine the coordinates of two endpoints on short-term
Canvas - & gt; MoveTo (140 + 140 + x1, y1);
Canvas - & gt; LineTo (140 + 140 + x2, y2);
//connect the two endpoints, the coordinates of the center of the circle (140140)
}
}
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Void__fastcall TForm1: : Timer1Timer (TObject * Sender)
{
AnsiString TSTR;
TDateTime DateTime.
Int x1, y1, x2, y2, L1, L2, L3;
Float h, m, s, deg;
L1=95; L2=85; L3=65;//points respectively, and the second, three needle when defining length
Canvas - & gt; Brush - & gt; Color=Form1 - & gt; Color;
Canvas - & gt; Pen - & gt; Color=Form1 - & gt; Color;
Canvas - & gt; The Ellipse (45, 45, 240, 240);
//the above three sentences draw a filled circle, the same as the background color effect is a picture for your used
DateTime=Time ();
H=HourOf (DateTime);
M=MinuteOf (DateTime);
S=SecondOf (DateTime);
//remove the system time and will, points, respectively after seconds apart assigned to h, m, s three variables
Canvas - & gt; Pen - & gt; Color=clBlue;
Canvas - & gt; Pen - & gt; Width=3;
M=m + s/60;
Deg (15 m) *=3.1416/30;
X1=L2 * cos (deg);
Y1=L2 * sin (deg);
Canvas - & gt; MoveTo (140140);
Canvas - & gt; LineTo (140-140 + x1, y1);
//more than eight words according to the m value to determine the Angle of the minute hand, then draw the blue minute hand
Canvas - & gt; Pen - & gt; Width=5;
H=h + m/60;
Deg (3-h) *=3.1416/6;
X1=L3 * cos (deg);
Y1=L3 * sin (deg);
Canvas - & gt; MoveTo (140140);
Canvas - & gt; LineTo (140-140 + x1, y1);
//not more than seven words in accordance with the h value to determine the Angle of the hour hand, then draw the blue hour hand
Canvas - & gt; Pen - & gt; Color=clRed;
Canvas - & gt; Pen - & gt; Width=1;
Deg (15 s) *=3.1416/30;
X1=L1 * cos (deg);
Y1=L1 * sin (deg);
Deg () - 15 - s *=3.1416/30.
X2=20 * cos (deg);
Y2=20 * sin (deg);
Canvas - & gt; MoveTo (140-140 + x1, y1);
Canvas - & gt; LineTo (140-140 + x2, y2);
//more than ten sentences according to the s value to determine the Angle of the second hand, then draw the length of L1 + 20 units of the red second hand
//20 of these units from the center of the circle in the opposite direction outstretched
}

CodePudding user response:

Positive solution,
Add
#include
#include
The
reference 4 floor response:
C/C + + code


Void__fastcall TForm1: : FormPaint (TObject * Sender)
{
Float deg.
Int x1, y1, x2, y2;
Canvas - & gt; Pen - & gt; Width=5;
for (int i=0; i<12. I++)
//this cycle in uniform distribution on the circumference of a circle of 12 short
{...

CodePudding user response:

The above said is very clear

CodePudding user response:

reference 5 floor xjq2003 reply:
truth,
Add
#include
#include
[Quote=reference 4 floor response:]
C/C + + code


Void__fastcall TForm1: : FormPaint (TObject * Sender)
{
Float deg.
Int x1, y1, x2, y2;
Canvas - & gt; Pen - & gt; Width=5;
for (int i=0; i<12. I++)
//this cycle in uniform distribution on the circumference of a circle of 12 short
{...
to borrow,
  • Related