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.

相关阅读 >>

Delphi 计算程序运行时间

Delphi请求http接口中文乱码问题

Delphi使用hough变换查找直线

Delphi xe6开发的android应用实现在线升级完成后自动安装apk代码(加说明)

Delphi 调用外部程序获取程序id,并能关闭该程序

Delphi android adb usb上读取设备信息

Delphi中使用directx截屏函数

Delphi 获取星期的函数

Delphi adoconnection连接 sqlserver

用tidftp控件实现ftp协议

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...