Author: Eber Irigoyen
Someone asked how to drag a TImage for example, and just playing with code I came
up with this quick (and dirty?) solution.
Answer:
There's an article here on how to drag windowed controls "Dragging controls and
forms the easy way", but that code doesn't work for TImages for example
My solution for such thing is simply put the Image inside a TPanel and from the
Image OnMouseDown call the code of the TPanel, thus resulting in being able to move
the image, here's the code:
1 procedure TForm1.Panel1MouseDown(Sender: TObject; Button: TMouseButton;
2 Shift: TShiftState; X, Y: Integer);
3 const4 SC_DragMove = $F012; {this is magic (undocumented)}5 begin6 ReleaseCapture;
7 panel1.perform(WM_SysCommand, SC_DragMove, 0);
8 end;
9 10 procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;
11 Shift: TShiftState; X, Y: Integer);
12 begin13 panel1mousedown(Sender, Button, Shift, X, Y)
14 end;
The same would work for resizing, or all the other things that can be done changing the constant (given that the image is aligned using alClient)