我是在form上放了一个image控件,这个控件控制范围,然后在mouseup中写了如下代码:
Image.canvas.Rectangle(Origin.x,Origin.y,MovePt.x,MovePt.y);
Lastpt := Point(x,y);//最后画的一个点
Drawing := False;
newshape(Origin, MovePt); //
SizeControl := TSizerControl.Create(self, shape);
fdragging:=false;
shape.BoundsRect:=frect;
Shape.Pen.Style := psDot;
Shape.Brush.Style := bsClear;
shape.Visible:=true;
procedure TForMain.newshape(TopLeft, BottomRight: TPoint);
begin
shape :=TShape.Create(self);
shape.parent := ScrollBox1 ;
if TopLeft.x > BottomRight.x then
Shape.Left := BottomRight.x
else
shape.Left := TopLeft.x;
if TopLeft.y > BottomRight.y then
shape.Top := BottomRight.y
else
shape.Top := TopLeft.y;
shape.Width := abs(BottomRight.x - TopLeft.x);
shape.Height := abs(BottomRight.y - TopLeft.y);
shape.Visible := true;
shape.Enabled := true;
end;