怎样用delphi做一个windows时钟?

怎样用delphi做一个windows时钟,急求谢谢... 怎样用delphi做一个windows时钟,急求谢谢 展开
 我来答
匿名用户
2013-11-17
展开全部
本程序运行后,有一个电子钟在桌面上。

1、对象的基本属性:

object Form1: TForm1 Left = 914 Top = -3 BorderIcons = [] BorderStyle = bsNone Caption = 'Form1' ClientHeight = 108 ClientWidth = 100 Color = clBackground TransparentColor = True Font.Charset = DEFAULT_CHARSET Font.Color = clWindowText Font.Height = -10 Font.Name = 'MS Sans Serif' Font.Style = [] OldCreateOrder = False PopupMenu = PopupMenu1 OnCreate = FormCreate OnPaint = formpaint OnResize = FormResize PixelsPerInch = 96 TextHeight = 13 object PopupMenu1: TPopupMenu Left = 80 Top = 72 object N1: TMenuItem Caption = '退出' OnClick = N1Click end end object Timer1: TTimer Left = 48 Top = 40 end object Timer2: TTimer OnTimer = Timer2Timer Left = 80 Top = 24 endend

2、程序的基本代码:

unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls, Menus;type TForm1 = class(TForm) PopupMenu1: TPopupMenu; N1: TMenuItem; Timer1: TTimer; Timer2: TTimer; procedure Timer2Timer(Sender: TObject); procedure formpaint(Sender: TObject); procedure FormResize(Sender: TObject); procedure FormCreate(Sender: TObject); procedure N1Click(Sender: TObject); private { Private declarations } hour,minute,second:word; oldminute,oldsecond:word; xcenter,ycenter,radius:integer; public { Public declarations } procedure drawhand(xcenter,ycenter,radius,backradius:integer;angle:real); procedure drawsecond; end;var Form1: TForm1;implementation{$R *.dfm}procedure Tform1.Timer2Timer(Sender: TObject); var hsec:word;begin oldminute:=minute; oldsecond:=second; decodetime(time,hour,minute,second,hsec); drawsecond; refresh; end;procedure TForm1.formpaint(Sender: TObject); var angle:real; I,x,y,size:integer;begin xcenter:=clientwidth div 2; ycenter:=clientheight div 2; if xcenter>ycenter then radius:=ycenter-10 else radius:=xcenter-10; canvas.Pen.Color:=clred; canvas.Pen.Mode:=pmcopy; canvas.Brush.Color:=clred; size:=radius div 50+1; for i:=0 to 11 do begin angle:=2*pi*(i+9)/12; x:=xcenter-round(radius*cos(angle)); y:= ycenter-round(radius*sin(angle)); canvas.Ellipse(x-size,y-size,x+size,y+size); end; {画分针} canvas.Pen.Width:=2; canvas.Pen.Color:=clred; angle:=2*pi*(minute+45)/60; drawhand(xcenter,ycenter,radius*90 div 100,0,angle); {画时针} canvas.Pen.Width :=4; canvas.Pen.Color:=clred; angle:=2*pi*(hour+9+minute/60)/12; drawhand(xcenter,ycenter,radius*70 div 100,0,angle); {画秒针} canvas.Pen.Width:=1; canvas.Pen.Color:=clred; canvas.Pen.Mode:=pmcopy; angle:=2*pi*(second+45)/60; drawhand(xcenter,ycenter,radius*30 div 30,0,angle);end;procedure tform1.drawhand(xcenter,ycenter,radius,backradius:integer;angle:real);begin canvas.MoveTo(xcenter-round(backradius*cos(angle)),ycenter-round(backradius*sin(angle)));canvas.LineTo(xcenter+round(radius*cos(angle)),ycenter+round(radius*sin(angle))); end; procedure tform1.drawsecond ; var angle,oldangle:real; begin oldangle:=2*pi*(oldsecond+45)/60; drawhand(xcenter,ycenter,radius,radius*30 div 100,oldangle); angle:=2*pi*(second+45)/60; drawhand(xcenter,ycenter,radius,radius*30 div 100,angle); end;procedure TForm1.FormResize(Sender: TObject);begin Refresh ; end;procedure TForm1.FormCreate(Sender: TObject);begin form1.Color:=getsyscolor(COLOR_DESKTOP); timer2timer(self); end;procedure TForm1.N1Click(Sender: TObject);begin close;end;end.

本程序在window98+delphi6中运行通过。
微测检测5.10
2023-05-10 广告
您好!建议咨 深圳市微测检测有限公司,已建立起十余个专业实验室,企业通过微测检测就可以获得一站式的测试与认 证解决方案;(EMC、RF、MFi、BQB、QI、USB、安全、锂电池、快充、汽车电子EMC、汽车手机互 联、语音通话质量),认证遇... 点击进入详情页
本回答由微测检测5.10提供
匿名用户
2013-11-17
展开全部
需要一个时间控件 Timer 下面是个代码 自己分析一下吧 看不太懂了可以加我QQ39518222我也是刚学的 咱们可以一起研究一下呀
unit Unit1;

interface

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

type
TForm1 = class(TForm)
Timer1: TTimer;
Timer2: TTimer;
procedure windowsposchange(var Msg:TWMWINDOWPOSCHANGING);
message WM_WINDOWPOSCHANGING;
procedure Timer2Timer(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure FormPaint(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormResize(Sender: TObject);
private
{ Private declarations }
Hour, Minute, Second: Word; {当前时间}
OldMinute, OldSecond: Word; {旧时间}
XCenter, YCenter, Radius: Integer; {当前窗体大小}
public
{ Public declarations }
procedure DrawHand (XCenter, YCenter, Radius,
BackRadius: Integer; Angle: Real);
procedure DrawSecond;
end;

var
Form1: TForm1;
oleft:Integer;
otop:Integer;
owidth:Integer;
oheight:Integer;
implementation

{$R *.dfm}

procedure TForm1.Timer2Timer(Sender: TObject);
begin
self.Caption := '桌面时钟 '+datetimetostr(now);
end;

procedure TForm1.Timer1Timer(Sender: TObject);
var
hesc:word;
begin
oldminute := minute;
oldsecond := second;
SysUtils.DecodeTime(time,hour,minute,second,hesc);

if oldminute = minute then
drawsecond
else
refresh;
end;

procedure tform1.DrawSecond;
var
Angle,OldAngle :real;
begin
oldangle := 2*pi*(oldsecond+45)/60;
drawhand(XCenter, YCenter, Radius,
Radius * 30 div 100, OldAngle);

angle := 2*pi*(second+45)/60;
drawhand(XCenter, YCenter, Radius,
Radius * 30 div 100, angle);
end;

procedure tform1.DrawHand(XCenter, YCenter, Radius,
BackRadius: Integer; Angle: Real);
begin
form1.Canvas.MoveTo(XCenter - Round (BackRadius * Cos (Angle)),
YCenter - Round (BackRadius * Sin (Angle)));
form1.Canvas.LineTo (
XCenter + Round (Radius * Cos (Angle)),
YCenter + Round (Radius * Sin (Angle)));
end;

procedure TForm1.FormPaint(Sender: TObject);
var
Angle: Real;
I, X, Y, Size: Integer;
begin
xcenter := clientwidth div 2;
ycenter := clientheight div 2;

if xcenter > ycenter then
radius := ycenter-10
else
radius := xcenter-10;

self.Canvas.Pen.Color := clblue;
self.Canvas.Pen.Mode := Graphics.pmCopy ;
self.Canvas.Brush.Color := clwhite;
size := radius div 50 +1;
for I := 0 to 11 do
begin
Angle := 2 * Pi * (I + 9)/12;
X := XCenter - Round(Radius*Cos(Angle));
Y := YCenter - Round(Radius*Sin(Angle));
Canvas.Ellipse (X - Size, Y - Size, X + Size, Y + Size);
end;

//画分针
self.Canvas.Pen.Width := 2;
self.Canvas.Pen.Color := clblue;
angle := 2*pi*(minute+45)/60;
DrawHand (XCenter, YCenter,
Radius * 90 div 100, 0, Angle);
Angle := 2 * Pi * (Hour + 9 + Minute / 60) / 12;//画时针
DrawHand (XCenter, YCenter,
Radius * 70 div 100, 0, Angle);

Canvas.Pen.Width := 1; //画秒针
Canvas.Pen.Color := clRed;
Canvas.Pen.Mode := pmNotXor;
Angle := 2 * Pi * (Second+45) / 60;
DrawHand (XCenter, YCenter, Radius,
Radius * 30 div 100, Angle);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
SELF.Timer1Timer(SELF);
OLEFT := LEFT;
OTOP := top;
owidth := width;
oheight := height;
self.Caption := '桌面时钟 '+ datetimetostr(now);
end;

procedure tform1.windowsposchange(var Msg:TWMWINDOWPOSCHANGING);
begin
Msg.WindowPos.x:=oleft;
Msg.WindowPos.y:=otop;
Msg.WindowPos.cx:=owidth;
Msg.WindowPos.cy:=oheight;
inherited;
end;

procedure TForm1.FormResize(Sender: TObject);
begin
Refresh;
end;

end.
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
匿名用户
2013-11-17
展开全部
Label1.caption:=datetostr(now)
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
匿名用户
2013-11-17
展开全部
这个可以找控件,或者自己画一个
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
匿名用户
2013-11-17
展开全部
你在网上找下吧。很Easy的
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(3)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式