Recent

Author Topic: ImgView32 image mouse panning [SOLVED]  (Read 2087 times)

Pe3s

  • Hero Member
  • *****
  • Posts: 547
ImgView32 image mouse panning [SOLVED]
« on: August 25, 2024, 07:52:36 am »
Hello, how can I improve the code so that it works, I mean moving the image with the mouse together with scrollbars?

Code: Pascal  [Select][+][-]
  1. var
  2.   IsPanning: Boolean = False;
  3.   LastPoint: TPoint;
  4.  
  5. procedure TForm1.ImgView32_1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  6. begin
  7.   if Button = mbLeft then
  8.   begin
  9.     IsPanning := True;
  10.     LastPoint := Point(X, Y);
  11.   end;
  12. end;
  13.  
  14. procedure TForm1.ImgView32_1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
  15. var
  16.   dx, dy: Integer;
  17. begin
  18.   if IsPanning then
  19.   begin
  20.     dx := X - LastPoint.X;
  21.     dy := Y - LastPoint.Y;
  22.  
  23.     ImgView32_1.Offset := Point(ImgView32_1.Offset.X + dx, ImgView32_1.Offset.Y + dy);
  24.  
  25.     LastPoint := Point(X, Y);
  26.   end;
  27. end;
  28.  
  29. procedure TForm1.ImgView32_1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  30. begin
  31.   if Button = mbLeft then
  32.     IsPanning := False;
  33. end;
  34.  
  35.  
« Last Edit: September 08, 2024, 10:06:47 pm by Pe3s »

 

TinyPortal © 2005-2018