我正在尝试将 tabControl1 设置为只读,但出于某种原因,这对我不起作用。
tabControl1.TabPages.IsReadOnly = True
给了我这个错误:
Error 1 Property 'IsReadOnly' is 'ReadOnly'.
当我尝试:
tabControl1.TabPages.ReadOnly = True
它给了我这个错误:
Error 1 'ReadOnly' is not a member of 'System.Windows.Forms.TabControl.TabPageCollection'.
怎么了?
答案 0 :(得分:0)
One option is to iterate over the control's within the TabControl TabPages
and enable or disable the controls. Here's a quick snippet I done that does exactly that. You can choose to: disable/enable all controls in the TabPages
or do it for single TabPages
if you choose.
Public Shared Sub EnableDisablePages(ByVal tbCon As TabControl, ByVal pg As TabPage, ByVal enabled As Boolean)
Try
'Single TabPage
If pg IsNot Nothing Then
For Each ctl As Control In pg.Controls
ctl.Enabled = enabled
Next
Else 'All TabPages...
If tbCon IsNot Nothing Then
For Each tp As TabPage In tbCon.TabPages
For Each cCon As Control In tp.Controls
cCon.Enabled = enabled
Next
Next
End If
End If
Catch ex As Exception
'Handle your exception...
End Try
End Sub
This can be used as so...
EnableDisablePages(TabControl1, Nothing, False) 'Disable all TabPage controls.
EnableDisablePages(Nothing, TabControl1.SelectedTab, False) 'Disable current TabPage.
EnableDisablePages(Nothing, TabControl1.SelectedTab, True) 'Enable current selected TabPage.
EnableDisablePages(TabControl1, Nothing, True) 'Enable all controls within all the TabPages.
This is only for the TabPages Controls
not the TabPage
itself as I don't think that is what you are wanting.