views:

408

answers:

5

Hi, I have created some custom controls (TCustomControl) in Delphi that I can move them at runtime but only one by one. How I can select two or more of these controls, at runtime again, and move them around all together with the mouse?

Thank you.

+3  A: 

If you can't find any simpler way, you can always do it manually. Keep a list of all the selected controls. When the drag operation begins, make another list, this one containing TPoint values indicating how far on both axes each control's Top and Left properties are from the mouse's position. Then, as the user drags the control, continually update the selected controls to keep them at the proper relative positions to the mouse pointer.

Mason Wheeler
I was thinking something like your suggestion though it only needs delta values of position for the master control I will move and apply those deltas to the other controls. So if control1 is changed .Left by 3 pixels and .Top 10 pixels then controlN.Left := controlN.Left + DeltaX; controlN.Top := controlN.Top + DeltaY; I have done some testing with this but I cannot move the rest of the controls while I move the master.
pani
+1  A: 

How about a commercial solution? The screen shot shows alignment tools, which would suggest that it supports multi-select.

Bruce McGee
This is the first library I looked at but I decided to implement it myself since I had already coded most of the functionality needed.
pani
+2  A: 

Another comercial solution would be from DevExpress: LayoutControl. It allows for drag and drop, grouping, full rearrange, hiding and adding of components at runtime.

Ralph Rickenbach
I really don't want to lock with a third party vendor, especially DevExpress, for something so simple.
pani
+1  A: 

I once used a component named handles, that if I remember correctly wasn't too difficult to update to the later versions of Delphi and supported multi-select.

skamradt
I used this component and added multi-select with some changes.The only visual bug is the mouse selection rectangle that goes under the controls (since I paint it on parent canvas) and that actual controls' offset is +2 pixels on both axis.Thank you.
pani
A: 

Hi Pani,

I am about to design something similar.

I hate to reinvent the wheel, because somewhere out there is a wheel design that will work much better than what I create and it will likely be more efficient and include ideas that I will not initially think of.

Where could I get some basic steps on how to do this? I'm guessing I'd start when the MouseDown event fires, then somehow add the mouse coordinates to the active control's Location property.

Could you point me to anything to get me started? There could even be a keyword that I could search on that would help me find my solution quicker.

Regards, ~Joe

jp2code
Ok, first of all 600 characters make pasting big parts of code difficult.See a part of the implementation here: http://pastebin.com/f394921f1Also note that since the controls I manipulate are custom made I choosed the faster way and used a TStretchHandle inside each control. If you want to implement for other controls you will have to make two lists, one that will host the controls, the other will hold TStretchHandle for each control and you will have to link mouse down, mouse move, etc for each of the control.If you need more help I'll be arround,Regards.
pani