开发者

Panels side by side taking up 50% width each

I have two panels: panelA, panelB in a panel: panelContainer.

开发者_运维技巧

How do I make panelA and panelB go side by side taking 50% width each of the panelContainer?


Use TableLayoutPanel with one row(100%) and two columns (50% each).


You can use SplitContainer instead of panel. Set IsSplitterFixed to true, in design mode set SplitterDistance to be half of SplitContainer's width and set the SplitterWidth to 1. Make sure that FixedPanel is set to none. Then at runtime it will maintain the ratio of panels widths.

The only problem is that you can't set SplitterWidth to zero so there will always be a slight distance between panels. If that's not a problem and if you don't need the panelContainer to actually be a panel for some reason, that's the way I would do it.


Check SplitterDistance Property. Override form resize and set this value = form.width / 2;

See more. https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.splitcontainer.splitterdistance?view=netframework-4.8

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜