隐藏 TabControl 上的控件
Hide Controls on TabControl
在 VS2013 VB 中工作,我有一个 TabControl,它在各种选项卡上有 Button 控件,名为 Button1、Button2 等。我想将可见的 属性 设置为 false表单加载期间的按钮,但它不起作用。我确定我遗漏了一些简单的东西,这是我的代码:
Dim ctl As Control
'Loop thru all controls
For Each ctl In Me.Controls
'Test that it is a Button and test for name
If (TypeOf ctl Is Button And Mid(ctl.Name, 1, 6) = "Button") Then
'Hide the Button
ctl.Visible = False
End If
Next
您需要查看标签页集合和控件集合。
尝试这样的事情:
Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load
Try
hideButtons()
Catch ex As Exception
MessageBox.Show(String.Concat("An error occurred ", ex.Message))
End Try
End Sub
Private Sub hideButtons()
For Each tp As TabPage In TabControl1.TabPages
For Each ctl As Control In tp.Controls
If (TypeOf ctl Is Button And Mid(ctl.Name, 1, 6) = "Button") Then
ctl.Visible = False
End If
Next
Next
End Sub
在 VS2013 VB 中工作,我有一个 TabControl,它在各种选项卡上有 Button 控件,名为 Button1、Button2 等。我想将可见的 属性 设置为 false表单加载期间的按钮,但它不起作用。我确定我遗漏了一些简单的东西,这是我的代码:
Dim ctl As Control
'Loop thru all controls
For Each ctl In Me.Controls
'Test that it is a Button and test for name
If (TypeOf ctl Is Button And Mid(ctl.Name, 1, 6) = "Button") Then
'Hide the Button
ctl.Visible = False
End If
Next
您需要查看标签页集合和控件集合。 尝试这样的事情:
Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load
Try
hideButtons()
Catch ex As Exception
MessageBox.Show(String.Concat("An error occurred ", ex.Message))
End Try
End Sub
Private Sub hideButtons()
For Each tp As TabPage In TabControl1.TabPages
For Each ctl As Control In tp.Controls
If (TypeOf ctl Is Button And Mid(ctl.Name, 1, 6) = "Button") Then
ctl.Visible = False
End If
Next
Next
End Sub