Create graphical transparent analog clock dynamically

Create graphical transparent analog clock dynamically

Create graphical transparent analog clock dynamically

This tutorial demonstrates how to create graphical transparent analog clock computer screen.

DownloadDownload This Tutorials

Bookmark:

Create graphical transparent analog clock dynamically

By using some basic trigonometric calculation we can find the drawing coordinates for each needle in analog clock. Hours, minutes and seconds converts to their respective coordinates to draw lines for clock needles. To rotate needles we need to first remove the previous needle from screen and then draw the new one with new coordinates. To erase previous one we set canvas pen mode to XOR.

To create transparent form we simply set form brush style to bsClear.

Transparent Analog clock

Here is the procedure to draw the nubers for the circle on a circular path.

procedure TForm1.ClockFrame(Sender: TObject);
Var
     A, R, Xo, Yo, X, Y : Integer;
Begin
     { Set center point }
     Xo:=Width Div 2;
     Yo:=Height Div 2;
     R:=Yo-30;

     { Set font properties }
     Canvas.Font.Style:=[fsBold];
     Canvas.Font.Name:='TimesNewRoman';

     { Set font background color to transparent . . . }
     Canvas.Brush.Style:=bsClear;

     { Display numbers in a circle from 1 to 12 }
     Canvas.Font.Size:=40;
     Canvas.Font.Color:=clBlack;
     For A:=1 to 12 Do
     Begin
          X:=Xo+Round(R*Sin(30*A*Pi/180));
          Y:=Yo-Round(R*Cos(30*A*Pi/180))-20;
          Canvas.TextOut(X,Y,IntToStr(A));
     End;

     Canvas.Font.Size:=35;
     Canvas.Font.Color:=clYellow;
     For A:=1 to 12 Do
     Begin
          X:=Xo+Round(R*Sin(30*A*Pi/180));
          Y:=Yo-Round(R*Cos(30*A*Pi/180))-20;
          Canvas.TextOut(X,Y,IntToStr(A));
     End;
End;

This one make the transparent form at startup.

procedure TForm1.FormCreate(Sender: TObject);
begin
     FirstDraw:=True;

     { Set Form background to transparent }
     Brush.Style:=bsClear;
end;

These procedures use to close the program if any key or mouse button press.

procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
     { Close the program if any key is pressed . . . }
     Close;
end;

procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
     { Close the program if mouse click . . . }
     Close;
end;

Download This Delphi Tutorials.

Download materials for this article (Delphi - Tutorials)

Download - transparent-analog-clock.ziptransparent-analog-clock.zip
       File size: 6 KB, File type: zip
       Total downloads: 1192, Upload date: February 10 - 2009

Download - transparent-analog-clock-exe.ziptransparent-analog-clock-exe.zip
       File size: 192 KB, File type: zip
       Total downloads: 885, Upload date: February 10 - 2009

silpa :: July 24-2009 :: 05:26 AM

send codings for analog clock in vb.net

Anas :: March 01-2011 :: 10:49 AM

please i like how you are given a good idea so please ill want you to send the correct procedures so that i can create my own in visual basic 6.0 waiting for you thanks.

Leave a comment