简体   繁体   中英

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 . Can anyone tell me why this is happening, and how to correct it?

The z-index of your controls is causing this behaviour. Try to play a little bit with the [Control].BringToFront() and [Control].SendToBack() methods.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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