我想询问是否有可能在tabcontrol中禁用选项卡。
这是禁用时代码的样子:
Public Sub TabControl1_Selecting(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TabControlCancelEventArgs) Handles TabControl1.Selecting
If e.TabPageIndex = 3 Then
e.Cancel = True
End If
End Sub
请参阅此代码:
Public Sub EnableTabs(ByVal Page As TabPage, ByVal bolFlag As Boolean)
EnableControls(Page.Controls, bolFlag)
End Sub
Private Sub EnableControls(ByVal Ctrls As Control.ControlCollection, ByVal bolFlag As Boolean)
For Each Ctrl As Control In Ctrls
Ctrl.Enabled = bolFlag
EnableControls(Ctrl.Controls, bolFlag)
Next
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'I have problems with this line
EnableTabs(TabControl1.TabPages(TabControl1.SelectedIndex) = 0, False)
End Sub
我是否可以在点击按钮时禁用标签?
让我知道!
谢谢,
此致 阿尔文
答案 0 :(得分:0)
试试这个:
Private Sub Button_Click( sender As Object, e As EventArgs) Handles Button.Click
Dim tabPage As TabPage
For Each tabPage In TabControl1.TabPages
If tabPage.Text ="TabPage1"
tabPage.Enabled =False
End If
Next
End Sub
或
Private Sub Button1_Click( sender As Object, e As EventArgs) Handles Button1.Click
TabControl1.TabPages(0).Enabled =false
End Sub
答案 1 :(得分:0)
又一个答案。
在某些时候,如果要禁用选项卡 - 请在适当的位置使用此代码
TabControl1.TabPages(x).Enabled = False
其中x是您要禁用的标签页的从零开始的索引。
当用户点击TabPage时,Selecting
事件将触发整个控件。使用e
eventargs参数,您可以看到正在选择的TabPage的索引。此事件中的代码检查是否已禁用,如果是,则取消选项卡单击。
Private Sub TabControl1_Selecting(sender As Object, e As TabControlCancelEventArgs) Handles TabControl1.Selecting
If e.TabPage.Enabled = False Then
e.Cancel = True
End If
End Sub
答案 2 :(得分:-1)
我已经回答了。无论如何,我想为你们分享一下。
我只需更改代码:
EnableTabs(TabControl1.TabPages(TabControl1.SelectedIndex) = 0, False)
为:
EnableTabs(TabControl1.TabPages(1), False)
此代码仅在选择/单击选项卡标题时不包含选项卡。我想我现在只使用这个。如果您有足够有用的其他代码源。请离开下面的答案部分。我喜欢听到他们所有人。
非常感谢。
此致 阿尔文
答案 3 :(得分:-1)
基于它,我已经有了自己的答案。我现在使用这个代码,例如我有3个标签,分别为0-2索引。
Public Sub Tab0Flag As Boolean
Public Sub Tab1Flag As Boolean
Public Sub Tab2Flag As Boolean
Public Sub TabControl1_Selecting(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TabControlCancelEventArgs) Handles TabControl1.Selecting
If e.TabPageIndex = 0 Then
e.Cancel = Tab0Flag
End If
If e.TabPageIndex = 1 Then
e.Cancel = Tab1Flag
End If
If e.TabPageIndex = 2 Then
e.Cancel = Tab2Flag
End If
End Sub
Private Sub EnableTabs(ByVal Tab0 As Boolean, ByVal Tab1 As Boolean, ByVal Tab2 As Boolean)
Tab0Flag = Tab0
Tab1Flag = Tab1
Tab2Flag = Tab2
End Sub
Private Sub frmG_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'I'll Only Disable the 2nd tab
EnableTabs(False, True, False)
End Sub