简体   繁体   中英

Resizing user control that is docked in Panel control does not resize Panel control - better solution?

I have a user control that has two size options (there is a button in the user control, to toggle between the two options) - something like section - collapsed/expanded.

This user control is placed on a Panel control and Docked to fill it.

I need this Panel to be re-sized according to the user control's size. I expected it to happen automatically, since user control is Docked to fill the Panel, but Panel's SizeChanged event is not triggered.

So my solution is to have an event SizeChanged for user control and eventhandler in container form, that adjusts the Panel's size correspondingly.

But shouldn't this work automatically (as I mentioned above)? If not, then why changes to user control's size is not triggering container control's SizeChanged event?

Well, you don't want Dock since that forces the control's size to match the panel size. To do it the other way around, you need to set the panel's AutoSize property to True, AutoSizeMode to GrowAndShrink. And use Padding or the control's Margin to tweak and make the panel a bit bigger.

Do keep in mind that the changing panel size tends to give you more layout problems with the rest of the window, stuff may have to move out of the way to provide space. FlowLayoutPanel tends to be the next choice. Or the panel's SizeChanged event when automatic layout can't tackle it anymore.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM