Mega Code Archive

 
Categories / Delphi / OOP
 

Dragging non windowed controls at run time

Title: dragging non-windowed controls at run-time Question: 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: procedure TForm1.Panel1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); const SC_DragMove = $F012; {this is magic (undocumented)} begin ReleaseCapture; panel1.perform(WM_SysCommand, SC_DragMove, 0); end; procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin panel1mousedown(Sender, Button, Shift, X, Y) 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) quote from this article: dragging controls and forms the easy way Changing the value of the constant used allows you to do this: $F000 (Center cursor on the form) $F001 (Resize from left) $F002 (Resize from right) $F003 (Resize from up) $F004 (Lock the bottom right corner of the form, the up left corner move for resize) $F005 (Same from bottom left corner) $F006 (Lock up right and left border, resize other) $F007 (Lock up and right border, resize other border) $F008 (Lock left and up border and resize other) $F009 (Drag from anywhere) $F010 (Put cursor centered at the upper order) $F020 (Auto-Minimize Form) $F030 (Auto-Maximize Form) $F040 (Stop! You don't want that, it will lock all mouse click and make you reboot) salu2 keep up coding EberSys