开发者

Stackpanel with widthstyle set to fill?

I am in a situation where I want to add usercontrols in a panel. This has to be in a topdown order.

I have done whats explained here to make it act like a stackpanel. However I want the width of each usercontrol to fill out the panel and not be a fixed size.

I tried using tablelayoutpanel and setting it grows attribute to 'add rows' but since I might be in a s开发者_如何学Cituation with more space the height is sometimes not constant because it wants to fill out the last row.


You can still use the TableLayoutPanel.

To add controls, you can use the TableLayoutPanel.Add(Control, int, int) to specify the control, row, and column to put it in (in your case, column would always be 0). You can add rows by modifying the TableLayoutPanel.RowCount property. You would then set the Control.Anchor property on each control you add so it will stretch to the TableLayoutPanel's width:

Button b = new Button();
b.Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top;
tableLayoutPanel1.Add(b, 0, 0);

AnchorStyles.Top prevents it from stretching to the entire row's height.

This is just a rudimentary outline, but you should be able to work out how to make it work for you from this information, as well as the MSDN page for TableLayoutPanel.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜