Mega Code Archive

 
Categories / Delphi / Graphic
 

How to move a TImage in a scrollbox with the mouse

Title: How to move a TImage in a scrollbox with the mouse var StartX, StartY, MoveX, MoveY: Integer; IsMoved: Boolean; implementation procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin if Button = mbLeft then begin IsMoved := True; StartX := X; StartY := Y; MoveX := X; MoveY := Y; Scrollbox1.DoubleBuffered := True; end; end; procedure TForm1.Image1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); begin if isMoved then begin if (X ) and ((Image1.Left Image1.Width 25) Scrollbox1.Width) then Image1.Left := Image1.Left (X - StartX); if (X MoveX) and (Image1.Left 0) then Image1.Left := Image1.Left (X - StartX); if (Y ) and ((Image1.Top Image1.Height 25) Scrollbox1.Height) then Image1.Top := Image1.Top (Y - StartY); if (Y MoveY) and (Image1.Top 0) then Image1.Top := Image1.Top (Y - StartY); MoveX := X; MoveY := Y; end; end; procedure TForm1.Image1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); var tr1, tr2: TRect; begin if Button = mbLeft then begin IsMoved := False; Scrollbox1.DoubleBuffered := False; end; end;