简体   繁体   English

码头样式进行控制

[英]Dock Style for control

I have a user control which contains 2 buttons at the top and a grid below it. 我有一个用户控件,该控件在顶部包含2个按钮,在其下方包含一个网格。 Let me name this as UC1 我将其命名为UC1

This UC1 is placed inside another user control UC2. 该UC1被放置在另一个用户控件UC2内部。

During some cases in UC2, i do not need 2 buttons on UC1 and hence i make those 2 buttons as visible false and set the grid's dock style to Fill. 在UC2中的某些情况下,我不需要UC1上的2个按钮,因此我将这2个按钮设置为可见的false,并将网格的停靠样式设置为Fill。

grid.Dock = DockStyle.Fill;

But in some cases, i need those 2 buttons on UC1, I make 2 buttons as visible true followed by settng grid's dock style to None 但是在某些情况下,我需要在UC1上使用这2个按钮,我将2个按钮显示为true,然后将grid的停靠样式设置为None

grid.Dock = DockStyle.None;

After setting DockStyle to none, the grid's width becomes smaller and doesn't fit the width of UC2. 将DockStyle设置为none之后,网格的宽度变小并且不适合UC2的宽度。

if i don't use DockStyle.None, then grid and button gets overlapped. 如果我不使用DockStyle.None,则网格和按钮会重叠。

How can i resolve the width of grid in UC1 to fit the width of UC2 ? 如何解决UC1中的网格宽度以适合UC2的宽度?

You should place a TableLayoutPanel first on CU1, set it to Fill. 您应该首先将TableLayoutPanel放在CU1上,将其设置为Fill。

Then in this table, create a row for the a panel that holds the two buttons, and a second row to hold CU2. 然后在此表中,为包含两个按钮的面板创建一行,并为容纳CU2创建第二行。 The extra panel and CU2 can then all be set to Fill. 然后可以将额外的面板和CU2全部设置为Fill。

To show or hide the buttons, simply set the row height of the panel's row to a proper value or zero. 要显示或隐藏按钮,只需将面板行的行高设置为适当的值或零即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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