473,396 Members | 2,059 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

tabstrip (disable(grey out) a specific tab)

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.

Nov 17 '05 #1
2 3400
hi,

do you mean controls in a tab or the actual tabpage?

if you want to disable the tabpage's content and if you have a button that
is clicked to enable/disable it try this in the button's click event:

//Replace item with the name of the item.
//You can also add more items and add the '.Enabled = false;' after the
item's name
item.Enabled = false;

--
Alvo von Cossel I of Germany
"tottigang" wrote:
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.

Nov 17 '05 #2
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.TabControl Extender
'
' Utilisation : 1. Add a regular TabControl to your form
' 2. In the " Windows Form Designer generated code "
section,
' replace System.Windows.Forms.TabControl by
TabControlEx (2 places)
' 3. In the Form_Load event (or a similar place), add this
line
' YourTabControlName.DrawMode =
TabDrawMode.OwnerDrawFixed
' 4. If you want to disable a tabpage, add this line
' YourTabControlName.DisablePage(YourTabPageName)
'
' Historique :
' Auteur Date Intervention
' ----------------- --------------- -------------------------------------------------
' Eric Moreau 2004/02/15 Création
'================================================= ====================================

Public Class TabControlEx
Inherits System.Windows.Forms.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

Public Sub DisablePage(ByRef pTabPage As TabPage)
With pTabPage
.Enabled = False
'.Text = "(* " & .Text & " *)"
End With
End Sub

Private Sub TabControlEx_DrawItem(ByVal sender As Object, ByVal e As
System.Windows.Forms.DrawItemEventArgs) Handles MyBase.DrawItem
Dim intOffsetLeft As Int32
Dim intOffsetTop As Int32
Dim r As RectangleF = RectangleF.op_Implicit(e.Bounds)
Dim r2 As RectangleF
Dim ItemBrush As New SolidBrush(Me.BackColor)
Dim b As Brush ' SolidBrush = New
SolidBrush(TabControl1.ForeColor)
If Me.TabPages(e.Index).Enabled Then
b = Brushes.Black
Else
b = Brushes.Gray
End If

Dim sf As New StringFormat
sf.Alignment = StringAlignment.Center
sf.LineAlignment = StringAlignment.Center

Dim im As Bitmap
If Me.TabPages(e.Index).ImageIndex <> -1 Then
im = CType(Me.ImageList.Images(Me.TabPages(e.Index).Ima geIndex),
Bitmap)
End If

If Me.TabPages(e.Index).ImageIndex <> -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.Selected) Then
e.Graphics.FillRectangle(ItemBrush, e.Bounds)
e.Graphics.DrawString(Me.TabPages(e.Index).Text, e.Font, b, r2,
sf)
'e.Graphics.DrawString(TabControl1.TabPages(e.Inde x).Text,
e.Font, Brushes.Red, r2, sf)
intOffsetLeft = 5
intOffsetTop = 5 '4
Else
e.Graphics.DrawString(Me.TabPages(e.Index).Text, e.Font, b, r2,
sf)
'e.Graphics.DrawString(TabControl1.TabPages(e.Inde x).Text,
e.Font, Brushes.Blue, r2, sf)
intOffsetLeft = 2
intOffsetTop = 2 '4
End If

If Me.TabPages(e.Index).ImageIndex <> -1 Then
Me.ImageList.Draw(e.Graphics, Convert.ToInt32(r.Left) +
intOffsetLeft, Convert.ToInt32(r.Top) + intOffsetTop,
Me.TabPages(e.Index).ImageIndex)
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.com> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.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.

Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: jerry.ranch | last post by:
I'm starting to learn about the tab control. How would I write an on open event procedure in VBA, that upon opening of the form, a specific tab opens (say tab 1)? Thanks Jerry
0
by: sakieboy | last post by:
I'm working with ASP.Net 1.1. I have a user control that displays a javascript/DHTML calendar (because the normal calendar is clunky-real estate issue). I am using Microsoft.Web.UI.Webcontrols for...
3
by: mcena | last post by:
Hi pals. I am wring this program and I am using the tabstrip control with about 6 tabs. I am not able to pass program control to a specific tab. In my program, the following code enables me to write...
3
ADezii
by: ADezii | last post by:
One frequently asked question at TheScripts is how to set focus/make active a specific Tab on a Tab Control other than clicking on it. Before I provide the answer, I feel as though a little summary...
4
ADezii
by: ADezii | last post by:
One frequently asked question at TheScripts is how to set focus/make active a specific Tab on a Tab Control other than clicking on it. Before I provide the answer, I feel as though a little summary...
4
by: hariadusumalli | last post by:
Hi, I added a tab control to my form. I need to add the tab pages to the control at run-time. But this is little different from the normal way. I need to display one specific tab to the right...
2
by: dmorand | last post by:
I've got a field in my database, and I want to retrieve all characters to the left of the first number value encountered. I'm not quite sure how to accomplish this Here is an example of a field...
1
by: Coolboy55 | last post by:
How do I open a form to a specific tab? Thanks, CB55
2
by: ncsthbell | last post by:
Hello, I have an application that opens on a 'Main Form' and that form has 10 different tab selections. I need to be able to position a certain user to one of the tabs as if they had clicked on the...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.