Diabling Tabpage

R

Raju Shrestha

I tried to disable a tabpage by using tp.Enabled = False. It disables
all the controls contained on that tabpage but still I can move focus to
that tabpage which is not as expected. What is the workaround of this
problem?
Appreciate for the answer.
Thanks

Raju Shrestha
 
C

Claes Bergefall

Try this:

Public Class TabControlEx
Inherits TabControl

Private Const WM_LBUTTONDOWN As Integer = &H201
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
If m.Msg = WM_LBUTTONDOWN Then
Dim pt As New Point(m.LParam.ToInt32)
Dim index As Integer
For index = 0 To Me.TabPages.Count - 1
If GetTabRect(index).Contains(pt) Then
If TabPages(index).Enabled Then
MyBase.WndProc(m)
End If
Exit Sub
End If
Next
End If
MyBase.WndProc(m)
End Sub

Protected Overrides Sub OnKeyDown(ByVal ke As
System.Windows.Forms.KeyEventArgs)
Dim currentIndex As Integer = Me.SelectedIndex
Dim index As Integer
If ke.KeyCode = Keys.Left AndAlso Not (ke.Alt AndAlso Not
ke.Control) Then
For index = currentIndex - 1 To 0 Step -1
If TabPages(index).Enabled Then
Me.SelectedIndex = index
Exit For
End If
Next
ke.Handled = True
ElseIf ke.KeyCode = Keys.Right AndAlso Not (ke.Alt AndAlso Not
ke.Control) Then
For index = currentIndex + 1 To TabPages.Count - 1
If TabPages(index).Enabled Then
Me.SelectedIndex = index
Exit For
End If
Next
ke.Handled = True
End If
MyBase.OnKeyDown(ke)
End Sub
End Class

/claes
 
H

Herfried K. Wagner [MVP]

* Raju Shrestha said:
I tried to disable a tabpage by using tp.Enabled = False. It disables
all the controls contained on that tabpage but still I can move focus to
that tabpage which is not as expected. What is the workaround of this
problem?

This code shows how to detect when the selected tab changes:

<http://www.google.de/[email protected]>

Maybe you can use it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top