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

Delphi與DirectX之DelphiX(4):初識TDXTimer(2)

編輯:Delphi

代碼文件:

unit Unit1;
interface
uses
 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
 Dialogs, DXClass, DXDraws, ComCtrls;
type
 TForm1 = class(TForm)
  DXDraw1: TDXDraw;
  DXTimer1: TDXTimer;
  TrackBar1: TTrackBar;
  procedure FormCreate(Sender: TObject);
  procedure DXTimer1Timer(Sender: TObject; LagCount: Integer);
  procedure TrackBar1Change(Sender: TObject);
 end;
var
 Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
 DXDraw1.Align := alClIEnt;
 TrackBar1.Align := alBottom;
 TrackBar1.Height := 23;
 TrackBar1.ShowSelRange := False;
 TrackBar1.Min := 0;
 TrackBar1.Max := 500;
 TrackBar1.Position := TrackBar1.Max div 2;
 DXTimer1.Interval := TrackBar1.Position;
 Randomize;
end;
procedure TForm1.DXTimer1Timer(Sender: TObject; LagCount: Integer);
var
 x1,y1,x2,y2: Integer;
begin
 {隨機位置}
 x1 := Random(DXDraw1.Width);
 y1 := Random(DXDraw1.Height);
 x2 := Random(DXDraw1.Width);
 y2 := Random(DXDraw1.Height);
 DXDraw1.Surface.Fill(0);
 with DXDraw1.Surface.Canvas do begin
  Brush.Color := Random($FFFFFF); {隨機顏色}
  Ellipse(x1, y1, x2, y2);
  Release;
 end;
 DXDraw1.Flip;
end;
procedure TForm1.TrackBar1Change(Sender: TObject);
begin
 DXTimer1.Interval := TrackBar1.Position;
end;
end.

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