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 学习 sql 语句 - insert、update、delete

Delphi “invalid floating point operation.”错误的解决方法

Delphi memo 循环往上往下滚动

Delphi中操作powerpoint幻灯片的示例代码

Delphi memo 的当前行、当前列与当前字符

Delphi for 循环的例子 多种用法

Delphi 实现文件分割合并

Delphi 横竖屏代码控制

Delphi + word = 数据库 + 公文处理

Delphi提示‘error loading midas.dll’的原因及解决方案

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



打赏

取消

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

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

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

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

评论

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