Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use TControl.Align := alCustom?

Tags:

layout

delphi

Simple question. I have a panel with 3 components. All of them are have Align := alRight. But the problem is that during runtime the order of them is not the same as designtime.

Can I instead use alCustom to force the order at the right border ? I use D2007.

like image 923
Roland Bengtsson Avatar asked Nov 27 '09 13:11

Roland Bengtsson


3 Answers

Yes, you can do any type of custom alignment. Just use the control's OnAlignInsertBefore() and OnAlignPosition() events. (These exist in Delphi 2007, but aren't published so they don't appear in the Object Inspector's Events tab; you can still assign them in code. I've shown the prototypes below; they're documented in the help file under TAlignInsertBeforeEvent and TAlignPositionEvent; you can also see CustomAlignInsertBefore and OnAlignInsertBefore. )

TAlignInsertBeforeEvent = function(Sender: TWinControl; 
  C1, C2: TControl): Boolean of object;

TAlignPositionEvent = procedure(Sender: TWinControl; Control: TControl;
  var NewLeft, NewTop, NewWidth, NewHeight: Integer;
  var AlignRect: TRect; AlignInfo: TAlignInfo) of object;

The documentation contains pretty good descriptions of the parameters to both methods.

In Delphi 2010, these events are published and appear in the Events tab of the Object Inspector.

I've never seen the problem you're having, though... Did you try setting all of them to alNone, moving them away from the right edge, and then re-setting Align := alRight in the order you want them to appear?

like image 125
Ken White Avatar answered Nov 20 '22 13:11

Ken White


Have a look at Demo2 from this download.

like image 43
Uli Gerhardt Avatar answered Nov 20 '22 14:11

Uli Gerhardt


You don't reveal much of the problem at hand, but I would have taken a look at the flowpanel instead.

When dropping controls on a flowpanel, a new order-property 'automagically' appear. You can set which way your controls should flow, and if you want space between the controls, you set the margins on each control.

A little clearification: The new 'order-property' is actually called 'ControlIndex', and will appear at the bottom of the object inspector.

like image 2
Vegar Avatar answered Nov 20 '22 14:11

Vegar