代碼文件:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DXDraws;
type
TForm1 = class(TForm)
DXDraw1: TDXDraw;
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
str: string;
begin
str := FormatDateTime('h:n:s:zz', Time); {獲取當前時間, 精確到毫秒}
DXDraw1.Surface.Fill($FF0000); {填充為紅色, 注意這個顏色格式是和 Html 的顏色順序一樣的}
DXDraw1.Surface.Canvas.Brush.Style := bsClear;
DXDraw1.Surface.Canvas.Font.Color := clYellow;
DXDraw1.Surface.Canvas.Font.Size := 16;
DXDraw1.Surface.Canvas.TextOut(10, 10, str);
DXDraw1.Surface.Canvas.Release; {釋放 Canvas 對象}
DXDraw1.Flip;
end;
{這和上面的功能一樣, 只是簡化了寫法}
procedure TForm1.Button2Click(Sender: TObject);
var
str: string;
begin
str := FormatDateTime('h:n:s:zz', Time);
DXDraw1.Surface.Fill(0); {填充黑色}
with DXDraw1.Surface.Canvas do begin
Brush.Style := bsClear;
Font.Color := clLime;
Font.Size := 16;
TextOut(10, 10, str);
Release; {釋放 Canvas 對象}
end;
DXDraw1.Flip;
end;
end.