偶这里有个用polygon的现成例子:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
point=record
x:integer;
y:integer;
end;
type
TForm1 = class(TForm)
procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure FormCreate(Sender: TObject);
procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
ploypoints:array of point; //动态数组
nums:integer;
omx,omy:integer;
nmx,nmy:integer;
drawf:boolean;
implementation
{$R *.DFM}
procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if button=mbleft then
begin
drawf:=true;
omx:=x;
omy:=y;
nmx:=x;
nmy:=y;
form1.Canvas.MoveTo(omx,omy);
SetLength(ploypoints,nums);
ploypoints[nums-1].x:=x;
ploypoints[nums-1].y:=y;
nums:=nums+1;
end
else
begin
SetLength(ploypoints,nums);
ploypoints[nums-1].x:=x;
ploypoints[nums-1].y:=y;
nums:=nums+1;
canvas.Pen.Mode :=pmCopy;
form1.canvas.Polygon(ploypoints);
canvas.Pen.Mode :=pmnotxor;
nums:=1;
drawf:=false;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Canvas.Brush.Color :=clYellow;
Canvas.Pen.Style :=psdot;
canvas.Pen.Mode :=pmnotxor;
nums:=1;
end;
procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if drawf=true then
begin
form1.Canvas.MoveTo(omx,omy);
form1.Canvas.LineTo(nmx,nmy);
form1.Canvas.MoveTo(omx,omy);
form1.Canvas.LineTo(x,y);
nmx:=x;
nmy:=y;
end;
end;
end.