本主题描述如何通过代码显示和隐藏停靠面板。 要获得关于创建和销毁停靠面板的信息,请参阅 创建和销毁停靠面板 主题。
显示和隐藏停靠面板
停靠面板的可视性由它的 DockPanel.Visibility 属性控制。 如果该属性值被设置为 DockVisibility.Visible,则面板是可视的。 如果该属性值被设置为 DockVisibility.Hidden,则该面板不被显示在屏幕上 (被隐藏)。
对于被停靠到窗体中的面板及其子面板,可以把 DockPanel.Visibility 属性设置为 DockVisibility.AutoHide。 这会启用面板的 自动隐藏功能。 对于浮动面板,把 DockPanel.Visibility 属性设置为 DockVisibility.AutoHide 不起作用。
要显示已被隐藏的面板,也可以调用它的 DockPanel.Show 方法。 此方法把面板的 DockPanel.Visibility 属性设置为 DockVisibility.Visible。 如果需要隐藏停靠面板,可以调用它的 DockPanel.Hide 方法。
通过 DockManager.HiddenPanels 集合,可以按索引访问已被隐藏的面板。
示例
下列代码演示了如何隐藏所有可视的浮动面板。 通过 DockManager.RootPanels 集合来访问可视的浮动面板。 这些面板的 DockPanel.FloatForm 属性指向一个有效的对象 (浮动窗体)。
C# | ![]() |
---|---|
int index = 0; // Iterate through the visible panels which are not owned by other panels. while(index < dockManager1.RootPanels.Count) { DockPanel panel = dockManager1.RootPanels[index]; // Hide the panel if it's floating. if(panel.FloatForm == null) index++; else panel.Hide(); } |
Visual Basic | ![]() |
---|---|
Dim index As Integer = 0 ' Iterate through the visible panels which are not owned by any other panels. While index < dockManager1.RootPanels.Count Dim panel As DockPanel = dockManager1.RootPanels(index) ' Hide the panel if it's floating. If (panel.FloatForm Is Nothing) Then index = index + 1 Else panel.Hide() End If End While |