Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect when child control resizes?

Is there a way for a parent control to detect when a child control resizes? I'm considering writing a panel control that resizes as it's child controls resize (similar to the way a HTML DIV element will expand to fit it's contents).

like image 713
Shannon Matthews Avatar asked Jan 16 '13 20:01

Shannon Matthews


2 Answers

To answer your actual question, I beleve that the AlignControls method of your windowed control is called when a child control is resized or moved.

like image 93
Andreas Rejbrand Avatar answered Nov 02 '22 10:11

Andreas Rejbrand


TControl and TWinControl have built-in support for handling auto-sizing for you. All you have to do is set the TControl.AutoSize property to True. It is declared as protected in TControl, so you will have to promote it to public or published if you want your component users to set it. Otherwise, just set it in your component's contructor.

You can override the virtual CanAutoSize() method if you want to customize how your parent control sizes itself relative to its children.

like image 4
Remy Lebeau Avatar answered Nov 02 '22 09:11

Remy Lebeau