2017년 2월 7일 화요일

[Delphi] How to pan an image with the mouse in Scrollbox

자료출처 : http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_25028583.html

Here is the correct coding. The FLastX/Y value needs to be adjusted by the amount that the image was moved.

procedure TForm1.Image1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
var
  Dx, Dy: Integer;
begin
  if FMouseIsDown then
  begin
    Dx := X - FLastX;
    Dy := y - FLasty;
   
    VertScrollBar.Position := VertScrollBar.Position - (Dy * Image1.height div vertscrollbar.Range);
    HorzScrollBar.Position := HorzScrollBar.Position - (Dx * Image1.width div horzscrollbar.Range);

    FLastX := X - Dx;
    FLastY := Y - Dy;
  end
end;

댓글 없음:

댓글 쓰기