1.使用Canvas画出任意的形状(就是拿鼠标在上面乱画) pts : TPoints; 参考?xid=17552 例子: procedure TForm1.FormCreate(Sender: TObject); begin pts := TPoints.Create; end; procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin isDraw := True; pts.RemoveAll; //清除上次画图数据 pts.Add(Point(X, Y)); image1.Canvas.Pen.Mode := pmCopy; image1.Canvas.MoveTo(X, Y); end; procedure TForm1.Image1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); begin if isDraw then begin pts.Add(Point(X, Y)); with image1.Canvas do begin LineTo(X, Y); end; end; end; procedure TForm1.Image1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin isDraw := False; end; procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction); begin if pts <> nil then pts.Free; end; 2.撤销上一次画图的操作 procedure TForm1.Button1Click(Sender: TObject); var i: integer; begin if pts.Count > 0 then begin with image1.Canvas do begin Pen.Mode := pmNotXor; MoveTo(pts.Items[0].X, pts.Items[0].Y); for i := 1 to pts.Count - 1 do begin LineTo(pts.Items[i].X, pts.Items[i].Y); end; Pen.Mode := pmCopy; end; end; pts.RemoveAll; end;