delphi寫的時鐘

2021-04-06 14:31:58 字數 4048 閱讀 9351

很久以前寫的程式了,要整理機器,只好放到這了

unit unit1;

inte***ce

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

hour, minute, second: word;

oldminute, oldsecond: word;

xcenter, ycenter, radius: integer;

public

procedure drawhand (xcenter, ycenter, radius,

backradius: integer; angle: real);

procedure drawsecond;

end;

varform1: tform1;

oleft:integer;

otop:integer;

owidth:integer;

oheight:integer;

implementation

procedure tform1.timer2timer(sender: tobject);

begin

self.caption := '桌面時鐘 '+datetimetostr(now);

end;

procedure tform1.timer1timer(sender: tobject);

varhesc:word;

begin

oldminute := minute;

oldsecond := second;

sysutils.decodetime(time,hour,minute,second,hesc);

if oldminute = minute then

drawsecond

else

refresh;

end;

procedure tform1.drawsecond;

varangle,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);

varangle: 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.

Delphi時鐘元件

開發環境 delphi 7 開發名稱 時鐘元件 開發說明 時鐘可以切換指標型風格和數字型風格,可以設定時 分 秒的數值和顯示顏色,可以開啟和暫停,可以設定顯示大小。最近在學習delphi,以不同的實現方式來體現學習的過程,剛開始直接在窗體上繪製時鐘,完成使用定時器後,又用執行緒實現時鐘的走動 見第一...

用js css 寫簡單時鐘

如下 doctype html en utf 8 時鐘 title text css 錶盤的圓 clock circle 中間圓點 clock point 鐘錶刻度 ul li ul li.hour 時針 clock hour 分針 clock minute 秒針 clock second styl...

C 呼叫Delphi寫的DLL

在c 中可以這樣呼叫 呼叫 這裡需要注意的是要外傳的pchar型別引數,在c 中對應使用stringbuilder,如果使用string沒有任何資訊傳出,如果使用ref string形式,則會出現記憶體錯誤。在c 中可以這樣呼叫 呼叫 經過測試 delphi中integer的引數使用c 中的int即...

DELPHI下讀取與設定系統時鐘

在delphi下讀取與設定系統時鐘 很多朋友都想在自己的程式中顯示系統時間 這在delphi中十分容易 利用datetostr date 及timetostr time 函式即可實現。二者的函式原型如下 function datetostr date tdatetime string functio...

用原生JS寫簡單的時鐘

這是一個簡單的時鐘方案,主要 是三個時針旋轉的思路,時鐘佈局省去。step 1.獲取時分秒轉針 var hour document.getelementbyid hour var min document.getelementbyid m var sec document.getelementbyi...