Here is a VB.Net class you can add to your project that gives you a real
Enabled property:
Option Strict On
'============== =============== =============== =============== =============== ===========
' Classe : TabControlEx.vb
'
' Auteur : Eric Moreau
' Concept S2i inc.
'
' Description : System.Windows. Forms.TabContro l Extender
'
' Utilisation : 1. Add a regular TabControl to your form
' 2. In the " Windows Form Designer generated code "
section,
' replace System.Windows. Forms.TabContro l by
TabControlEx (2 places)
' 3. In the Form_Load event (or a similar place), add this
line
' YourTabControlN ame.DrawMode =
TabDrawMode.Own erDrawFixed
' 4. If you want to disable a tabpage, add this line
' YourTabControlN ame.DisablePage (YourTabPageNam e)
'
' Historique :
' Auteur Date Intervention
' ----------------- --------------- -------------------------------------------------
' Eric Moreau 2004/02/15 Création
'============== =============== =============== =============== =============== ===========
Public Class TabControlEx
Inherits System.Windows. Forms.TabContro l
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.Cou nt - 1
If GetTabRect(inde x).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.KeyEventA rgs)
Dim currentIndex As Integer = Me.SelectedInde x
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.SelectedInde x = 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.SelectedInde x = index
Exit For
End If
Next
ke.Handled = True
End If
MyBase.OnKeyDow n(ke)
End Sub
Public Sub DisablePage(ByR ef pTabPage As TabPage)
With pTabPage
.Enabled = False
'.Text = "(* " & .Text & " *)"
End With
End Sub
Private Sub TabControlEx_Dr awItem(ByVal sender As Object, ByVal e As
System.Windows. Forms.DrawItemE ventArgs) Handles MyBase.DrawItem
Dim intOffsetLeft As Int32
Dim intOffsetTop As Int32
Dim r As RectangleF = RectangleF.op_I mplicit(e.Bound s)
Dim r2 As RectangleF
Dim ItemBrush As New SolidBrush(Me.B ackColor)
Dim b As Brush ' SolidBrush = New
SolidBrush(TabC ontrol1.ForeCol or)
If Me.TabPages(e.I ndex).Enabled Then
b = Brushes.Black
Else
b = Brushes.Gray
End If
Dim sf As New StringFormat
sf.Alignment = StringAlignment .Center
sf.LineAlignmen t = StringAlignment .Center
Dim im As Bitmap
If Me.TabPages(e.I ndex).ImageInde x <> -1 Then
im = CType(Me.ImageL ist.Images(Me.T abPages(e.Index ).ImageIndex),
Bitmap)
End If
If Me.TabPages(e.I ndex).ImageInde x <> -1 Then
r2 = New RectangleF(r.X + (im.Width \ 2), r.Y, r.Width,
r.Height)
Else
r2 = New RectangleF(r.X, r.Y, r.Width, r.Height)
End If
If CBool(e.State And DrawItemState.S elected) Then
e.Graphics.Fill Rectangle(ItemB rush, e.Bounds)
e.Graphics.Draw String(Me.TabPa ges(e.Index).Te xt, e.Font, b, r2,
sf)
'e.Graphics.Dra wString(TabCont rol1.TabPages(e .Index).Text,
e.Font, Brushes.Red, r2, sf)
intOffsetLeft = 5
intOffsetTop = 5 '4
Else
e.Graphics.Draw String(Me.TabPa ges(e.Index).Te xt, e.Font, b, r2,
sf)
'e.Graphics.Dra wString(TabCont rol1.TabPages(e .Index).Text,
e.Font, Brushes.Blue, r2, sf)
intOffsetLeft = 2
intOffsetTop = 2 '4
End If
If Me.TabPages(e.I ndex).ImageInde x <> -1 Then
Me.ImageList.Dr aw(e.Graphics, Convert.ToInt32 (r.Left) +
intOffsetLeft, Convert.ToInt32 (r.Top) + intOffsetTop,
Me.TabPages(e.I ndex).ImageInde x)
End If
End Sub
End Class
--
HTH
Éric Moreau, MCSD, Visual Developer - Visual Basic MVP
(
http://aspnet2.com/mvp.ashx?EricMoreau)
Conseiller Principal / Senior Consultant
Concept S2i inc. (
www.s2i.com)
"tottigang" <si****@gmail.c om> wrote in message
news:11******** *************@o 13g2000cwo.goog legroups.com...
Hi,
I have a tabstrip and I have some tabs in it. On the first page, all
the tabs are enabled, I need to disbale part of the tabs at a specific
point in the application and again enable them. I have a hard time
doing this. This is concerned with a production issue. Could anyone
please suggest me a solution to this.
I appreciate your time and help.
Thanks and Regards,
Sita.