简体   繁体   English

更改 Winforms 用户控件中的 Dock 属性

[英]Changing the Dock property in a Winforms user control

I'm trying to create a button that will hide the panel that I have docked at the centre of my user control.我正在尝试创建一个按钮,该按钮将隐藏我停靠在用户控件中心的面板。

My form is laid out like so:我的表格布局如下:

toolStrip1 (docked to top)
topPanel (docked to fill)
bottomPanel (docked to bottom)

I have the following code:我有以下代码:

Private Sub ShowHideTopPanel()
    If topPanel.Visible Then
        topPanel.Visible = False
        bottomPanel.Dock = DockStyle.Fill
    Else
        topPanel.Visible = True
        bottomPanel.Dock = DockStyle.Bottom
    End If
End Sub

This works to an extent.这在一定程度上有效。 However, when the bottomPanel is set to Fill it seems to fill the entire control, and not just up to toolStrip1 .但是,当bottomPanel设置为 Fill 时,它似乎会填充整个控件,而不仅仅是toolStrip1 Can anyone tell me why this is happening, and how to correct it?谁能告诉我为什么会发生这种情况,以及如何纠正它?

The z-index of your controls is causing this behaviour.您的控件的 z-index 导致了这种行为。 Try to play a little bit with the [Control].BringToFront() and [Control].SendToBack() methods.尝试使用[Control].BringToFront()[Control].SendToBack()方法。

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

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