我在Windows窗体中有一个TableLayoutPanel控件。现在,我在该TableLayoutPanel中有4个Panel控件,如单元格(0,0)中的Panel1,单元格(0,1)中的Panel2,单元格(1,0)中的Panel3和单元格(1,1)中的Panel4。
现在,我想将Panel4移到Panel1并隐藏Panel1。这该怎么做?
与子控件位置进行交互的TableLayoutPanel
支持GetCellPosition
和SetCellPosition
方法。
可以使用以下方法交换两个子控件的位置。
Private Shared Sub SwapPosition(c1 As Control, c2 As Control)
Dim tlp As TableLayoutPanel = TryCast(c1.Parent, TableLayoutPanel)
If tlp Is c2.Parent AndAlso tlp IsNot Nothing Then
Dim posC1 As TableLayoutPanelCellPosition = tlp.GetCellPosition(c1)
Dim posC2 As TableLayoutPanelCellPosition = tlp.GetCellPosition(c2)
tlp.SetCellPosition(c2, posC1)
tlp.SetCellPosition(c1, posC2)
End If
End Sub
就隐藏子控件而言,可以将其从TableLayoutPanel
的控件集合中删除,也可以在控件上调用Hide
方法。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句