程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> Delphi >> Delphi與DirectX之DelphiX(3):初識TDXDraw(2)

Delphi與DirectX之DelphiX(3):初識TDXDraw(2)

編輯:Delphi

代碼文件:

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.

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved