Move certain controls at runtime

I would like to move certain controls at runtime (buttons, imagepanel) with the mouse. I would also like them to be layed out in a grid after moving. I hope this is clear. Please supply some sample code. Thanks a bunch.
mdlittleAsked:
Who is Participating?
 
Mohammed NasmanSoftware DeveloperCommented:
try this article, it worked fine with Delphi 2005 for win32
http://www.delphi-central.com/movecontrun.aspx
0
 
paulb1989Commented:
The following component allows you to move controls at runtime:

http://www.towebi.se/development/rtdesign/rtdindex.htm
0
 
mdlittleAuthor Commented:
Thanks, unfortunately these do not work with Delphi 2005. I should have specified my environment.
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

 
BlackTigerXCommented:
do you mean in Delphi 2005, in the .NET part?
0
 
mdlittleAuthor Commented:
Delphi 2005 in the VCL mode. I also tried the above example from mnasman and it is not really a good example. The form drags, all controls on message boxes drag, etc. it is not very clean.

0
 
LFLFMCommented:
Here is a simple enough method to move a button at runtime (hold ctrl+shift to drag):

procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
     if Shift = [ssCtrl,ssShift] then
     begin
          button1.Left := x;
          button1.Top := y;
     end;
end;

If you want to have it snap to a grid of 20x20:

          button1.Left := (round(x/20)*20);
          button1.Top := (round(y/20)*20);

Math to the snap:
eg. mouse is at 45x67
45 / 20 = 2.25, rounded down to 2,  2x20 = 40
67 / 20 = 3.35, rounded down to 3,  3x20 = 60



TShiftState is a set of values:
ssShift      The Shift key is held down.
ssAlt      The Alt key is held down.
ssCtrl      The Ctrl key is held down.
ssLeft      The left mouse button is held down.
ssRight      The right mouse button is held down.
ssMiddle      The middle mouse button is held down.
ssDouble      The mouse was double-clicked.


Hope this helps... =)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.