-1

I'm trying to set my tabControl1 to read-only, but for some reason this is not working for me.

tabControl1.TabPages.IsReadOnly = True

gives me this error:

Error   1   Property 'IsReadOnly' is 'ReadOnly'.

When i try:

tabControl1.TabPages.ReadOnly = True

it gives me this error:

Error   1   'ReadOnly' is not a member of 'System.Windows.Forms.TabControl.TabPageCollection'.

Whats wrong?

JefE
  • 137
  • 1
  • 2
  • 12
  • Don't think there is any kind of read only ability for the TabControl itself or the TabPages within. You could **disable** the entire thing, but that's not the same as read only. You'll have to iterate over the controls within and toggle their ReadOnly() properties manually. – Idle_Mind Jul 13 '15 at 18:38
  • Please check out [this](https://stackoverflow.com/questions/418006/how-can-i-disable-a-tab-inside-a-tabcontrol) relevant question. – Saragis Jul 13 '15 at 18:45

1 Answers1

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.

Trevor
  • 7,777
  • 6
  • 31
  • 50