unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    procedure FormMouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure FormPaint(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}
uses
  GDIPOBJ,GDIPAPI;
var
  i:Integer = 0;
  PtArr:array of TGPPoint;
procedure TForm1.Button1Click(Sender: TObject);
begin
  i:=0;
  SetLength(PtArr,i);
  Text:=IntToStr(i);
  Repaint;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  Repaint;
end;

procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  Canvas.Ellipse(x-2,y-2,x+2,y+2);
  Inc(i);
  SetLength(PtArr,i);
  PtArr[i-1]:=MakePoint(x,y);
  Text:=IntToStr(i);
end;

procedure TForm1.FormPaint(Sender: TObject);
var
  g:TGPGraphics;
  p:TGPPen;
begin
  g:=TGPGraphics.Create(Canvas.Handle);
  g.Clear(aclWhite);
  p:=TGPPen.Create(aclRed,2);

  {如果是动态数组的话, 需要 @PtArr, 但动态数组本身就是个指针}
  g.DrawPolygon(p,PGPPoint(PtArr),Length(PtArr));

  p.Free;
  g.Free;
end;

end.

posted on 2010-12-31 10:54  巅枫  阅读(642)  评论(0编辑  收藏  举报