2

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.

Argalatyr
  • 4,639
  • 3
  • 36
  • 62
pani
  • 1,075
  • 6
  • 13

4 Answers4

3

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 M. Rickenbach
  • 12,893
  • 5
  • 29
  • 49
  • I really don't want to lock with a third party vendor, especially DevExpress, for something so simple. – pani Aug 13 '09 at 15:27
2

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
  • 82,511
  • 50
  • 270
  • 477
  • 1
    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 Aug 13 '09 at 15:25
1

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
  • 15,366
  • 2
  • 36
  • 53
  • 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 Aug 13 '09 at 21:08
0

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

Bruce McGee
  • 15,076
  • 6
  • 55
  • 70
  • 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 Aug 13 '09 at 15:34