丿Clover灬夢 发表于 2013-9-20 22:51:53

鼠标画矩形

procedure TfrmCanvas.imgImageMouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
with imgImage do
begin
    oldx := x;
    oldy := y;
    Canvas.Brush.Style := bsClear;//画刷填充方式
    Canvas.Pen.Style := psDot; //线条类型
    Canvas.Pen.Mode := pmXor;
    Canvas.Pen.Color := clRed;
    rold := Rect(0, 0, 0, 0); //创建一个矩形对象
end;

if ssright in Shift then
begin
   imgImage.Picture.Bitmap := nil;
end;
end;

procedure TfrmCanvas.imgImageMouseMove(Sender: TObject; Shift: TShiftState;
X, Y: Integer);
begin
if not (ssleft in Shift) then Exit;
with imgImage do
begin
    Canvas.Rectangle(rold);//Rectangle根据提供的两个点或一个矩形区域绘制一个矩形
    Canvas.Rectangle(oldx, oldy, x, y);
    rold := Rect(oldx, oldy, x, y);
end;
end;

procedure TfrmCanvas.imgImageMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
with imgImage do
begin
    Canvas.Pen.Style := psSolid;
    Canvas.Pen.Mode := pmCopy;
    Canvas.Pen.Color := clRed;
    Canvas.Rectangle(rold);
end;
end;问题是在MouseMove事件中    Canvas.Rectangle(rold);//Rectangle根据提供的两个点或一个矩形区域绘制一个矩形
   Canvas.Rectangle(oldx, oldy, x, y);
    rold := Rect(oldx, oldy, x, y);
主要是实现了什么,求告知。。。谢谢!!!
页: [1]
查看完整版本: 鼠标画矩形