我想遍历表单中的所有面板并设置visible属性。 您能告诉我所有面板的存放位置吗?
Public Function ShowHide(PanelName As String)
For Each sth As Panel In Form.Panels
If sth.Name <> PanelName Then
sth.visible = False
Else
sth.visible = True
End If
Next
End Function
答案 0 :(得分:1)
您可以使用OfType()
方法仅遍历特定类型的控件:
products_ean.id
或者如果要单行执行:
Public Sub ShowHide(PanelName As String)
For Each sth As Panel In Me.Controls.OfType(Of Panel)()
If sth.Name = PanelName Then
sth.Visible = True
Else
sth.Visible = False
End If
Next
End Sub
答案 1 :(得分:0)
尝试一下:
Public Sub ShowHide(PanelName As String)
For Each sth As Control In Me.controls
If TypeOf sth Is Panel Then
If sth.Name <> PanelName Then
sth.Visible = False
Else
sth.Visible = True
End If
End If
Next
End Sub