开发者

Make UserControl resize when Dock = Fill

开发者 https://www.devze.com 2023-02-17 15:18 出处:网络
I have a problem with UserControl that I\'m crafting. It consists of TableLayoutPanel with another TableLa开发者_StackOverflow社区youtPanel in it with ListView inside. I want to make it resizable so t

I have a problem with UserControl that I'm crafting. It consists of TableLayoutPanel with another TableLa开发者_StackOverflow社区youtPanel in it with ListView inside. I want to make it resizable so that it will fit in left panel of my app and behave somewhat like Toolbox in Visual Studio. The problem is that my control doesn't scale when I resize panel.

UserControl is embedded in panel with Dock = Fill and Anchor = Tob, Left, Bottom, Right. Also all controls in it are made that way. How can I fix this?

EDIT: It's WinForms, not XAML.


Use a split panel and put your UserControl in the left panel and Dock.Fill it.


You're probably looking for the AutoSize properties on the TableLayoutPanel and the AutoSize ColumnType of that panel. You can achieve something like a Dock = Fill by simply auto-sizing the table layout panel (GrowAndShrink) so that it will always fit your inner control. Please post your designer code to see how you embedded the controls in which other control.


I suspect your resize problem come from your resizing strategy of control inside the TableLayoutPanel.

The table layout panel is tricky. Regarding the resize strategy you want to follow inside a cell of the table panel, the control in the cell have either to be Dock.Fill or Anchor = Top, Left, Bottom, Right.

Basically:

  • Il you want the grid cell to adapt to the size of the control, then have the control in the cell Anchor = Top, Left, Bottom, Right and set the row/column to autosize.

  • If you want the control in the cell to adapt to the cell size, use Dock.Fill on it and use a percentage or a absolute value to size your cell.

The behavior of the TableLayoutPanel is best described in the MSDN documentation.

0

精彩评论

暂无评论...
验证码 换一张
取 消