Search code examples
delphidelphi-2009

How to make a controll stick to its parent borders on resize?


I have a TGroupBox as a parent and i want to place a button inside it, and make it so the button would stick to the top right corner of groupbox.

The problem is, TGroupBox does not have the method OnResize, so i don't know how to tell a button where should it move after groupbox was resized.

Is there any way to make it happen?

Thank you


Solution

  • Set the button's Anchors property to include akTop and akRight. When its parent's size changes, it will move to keep its top and right offsets constant relative to the edges of the parent control. The default value has akLeft instead. (If both akLeft and akRight are set, then the button's width will grow and shrink with its parent.)

    Between the Align, Anchors, and Constraints properties, you will rarely have to write any of your own code to handle changes to a parent's size.