delphi 时钟


unit U1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;

type
TForm1 = class(TForm)
Timer1: TTimer;
Shape1: TShape;
Shape2: TShape;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
procedure FormPaint(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure FormKeyPress(Sender: TObject; var Key: Char);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
const pi=3.14159;

implementation

{$R *.dfm}

procedure TForm1.FormPaint(Sender: TObject);
var
x1,y1:integer;
a:real;
datetime,hour,minute,second:Tdatetime;
begin
datetime:=time;
form1.Caption:=timetostr(datetime);
hour:=datetime;
if hour>=0.5 then
hour:=hour-0.5;
a:=hour*pi*4;
x1:=round(sin(a)*60+268);
y1:=round(148-cos(a)*60);
canvas.pen.color:=clblack;
canvas.Pen.Width:=2;
with canvas do
begin
moveto(268,148);
lineto(x1,y1);
end;
minute:=frac(datetime*24);
a:=minute*2*pi;
x1:=round(sin(a)*65+268);
y1:=round(148-cos(a)*65);
canvas.Pen.Color:=clblack;
canvas.Pen.Width:=1;
with canvas do
begin
moveto(268,148);
lineto(x1,y1);
end;
second:=frac(datetime*24*60);
a:=second*2*pi;
x1:=round(sin(a)*80+268);
y1:=round(148-cos(a)*80);
canvas.Pen.Color:=clblack;
canvas.Pen.Width:=1;
with canvas do
begin
moveto(268,148);
lineto(x1,y1);
end;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
var
x1,y1:integer;
a:real;
datetime,hour,minute,second:TDatetime;
begin
refresh;
datetime:=time;
form1.Caption:=timetostr(datetime);
hour:=datetime;
if hour>=0.5 then
hour:=hour-0.5;
a:=hour*pi*4;
x1:=round(sin(a)*60+268);
y1:=round(148-cos(a)*60);
canvas.pen.color:=clblack;
canvas.Pen.Width:=2;
with canvas do
begin
moveto(268,148);
lineto(x1,y1);
end;
minute:=frac(datetime*24);
a:=minute*2*pi;
x1:=round(sin(a)*65+268);
y1:=round(148-cos(a)*65);
canvas.Pen.Color:=clblack;
canvas.Pen.Width:=1;
with canvas do
begin
moveto(268,148);
lineto(x1,y1);
end;
second:=frac(datetime*24*60);
a:=second*2*pi;
x1:=round(sin(a)*80+268);
y1:=round(148-cos(a)*80);
canvas.Pen.Color:=clblack;
canvas.Pen.Width:=1;
with canvas do
begin
moveto(268,148);
lineto(x1,y1);
end;
end;

procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
begin
form1.Close;
end;

end.

联系电话:
020-00000000
联系电话:
020-00000000
联系电话:
020-12345678