我希望能够在图像上绘制一个FocusRect,保持图像的宽高比。我的问题是,FocusRect仅取决于鼠标的y坐标。我不知道如何让矩形依赖于鼠标的x和y坐标...以下是我的代码:
procedure TForm1.AuswahlRechteck; //Due to this procedure it doesn't matter in which corner the rectangle begins
begin
Image1.Canvas.DrawFocusRect(Rect(X0,Y0,MX,MY));
Image1.Canvas.DrawFocusRect(Rect(X0,MY,MX,Y0));
Image1.Canvas.DrawFocusRect(Rect(MX,MY,X0,Y0));
Image1.Canvas.DrawFocusRect(Rect(MX,Y0,X0,MY));
end;
procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
X0:=X;
MX:=X;
Y0:=Y;
MY:=Y;
AuswahlRechteck;
InMove:=true;
end;
procedure TForm1.Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if InMove then
begin
AuswahlRechteck;
MY:=Y;
MX:=X;
if (((MX < X0) AND (MY > Y0)) OR ((MX > X0) AND (MY < Y0))) then MX:=Round(X0-((MY-Y0)*Image1.Width/Image1.Height))
else MX:=Round(X0+((MY-Y0)*Image1.Width/Image1.Height));
AuswahlRechteck;
end;
end;
有人能帮我吗?
亨利