By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,219 Members | 2,361 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,219 IT Pros & Developers. It's quick & easy.

Gray-out the text on the tab control display?

P: n/a
I would like to control entry into one or more of the tabs
I have set up on my Tab control based on set rules. Does
anyone know how to grey-out the text so that a user will
see that they do not have access to that particular tab?

I tried setting the enabled = false for the given tab, but it only seems to work in the form assembly section (that
is, if I do it after the form is loaded through a
function, it doesn't seem to work), and doing that
disables the controls on the tab, but does not grey out
the text of the tab display itself.

Thanks

K


Nov 20 '05 #1
Share this Question
Share on Google+
13 Replies


P: n/a
I assume you don't know before loading the form which to enable/disable? If
so a contructor passed a tabindex would work fine.

I also assume that you have tried setting the enabled property for the
particular tab page that you want disabled...

Is this true?

Shane
"KMiller" <an*******@discussions.microsoft.com> wrote in message
news:05****************************@phx.gbl...
I would like to control entry into one or more of the tabs
I have set up on my Tab control based on set rules. Does
anyone know how to grey-out the text so that a user will
see that they do not have access to that particular tab?

I tried setting the enabled = false for the given tab,

but
it only seems to work in the form assembly section (that
is, if I do it after the form is loaded through a
function, it doesn't seem to work), and doing that
disables the controls on the tab, but does not grey out
the text of the tab display itself.

Thanks

K

Nov 20 '05 #2

P: n/a
At the time the form is assembled, I DO NOT know.
However, shortly thereafter (during the loading process),
I DO know whether they have access or not to the
particular tab. It's at this time when I'm attempting to
disable (gray-out) the tab text, but nothing works.

I've tried setting the enabled property to false for the
tab, but doing that does nothing to the tab text display,
and users have no way of knowing they DO NOT have access
to the tab other then by clicking into it and finding out
that nothing works because all the controls have been
disabled. Leaving the functionality this way is
inadequate and out of spec.

-----Original Message-----
I assume you don't know before loading the form which to enable/disable? Ifso a contructor passed a tabindex would work fine.

I also assume that you have tried setting the enabled property for theparticular tab page that you want disabled...

Is this true?

Shane
"KMiller" <an*******@discussions.microsoft.com> wrote in messagenews:05****************************@phx.gbl...
I would like to control entry into one or more of the tabs
> I have set up on my Tab control based on set rules. Does > anyone know how to grey-out the text so that a user will > see that they do not have access to that particular tab? >
> I tried setting the enabled = false for the given tab,

but
> it only seems to work in the form assembly section (that > is, if I do it after the form is loaded through a
> function, it doesn't seem to work), and doing that
> disables the controls on the tab, but does not grey out > the text of the tab display itself.
>
> Thanks
>
> K

.

Nov 20 '05 #3

P: n/a
Hi K,

wow, I see your point.

I thought I had it fixed in my app too but my titles aren't disabled either.

You can do ownerdrawn fixed and change the color of the font easy enough.

Private Sub TabControl1_DrawItem(ByVal sender As Object, ByVal e As
System.Windows.Forms.DrawItemEventArgs) Handles TabControl1.DrawItem
Dim tp As TabPage
Dim layoutrct As New RectangleF(e.Bounds.Left, e.Bounds.Top,
e.Bounds.Width, e.Bounds.Height)
Dim sf As New StringFormat(StringFormatFlags.FitBlackBox)
sf.Alignment = StringAlignment.Center
sf.LineAlignment = StringAlignment.Center

tp = TabControl1.TabPages(e.Index)
If Not tp.Enabled Then
'for some reason not printing the 3-d part--tried to print twice
with offset but no luck
e.Graphics.DrawString(tp.Text, e.Font, SystemBrushes.ControlLight,
layoutrct)
layoutrct.Offset(2, 2)
e.Graphics.DrawString(tp.Text, e.Font, SystemBrushes.ControlDark,
layoutrct) 'SolidBrush(e.BackColor), layoutrct)
Else
e.Graphics.DrawString(tp.Text, e.Font,New SolidBrush(e.BackColor),
layoutrct)
End If
End Sub

This works if items are not enabled. But there must be an easier way--also
they shouldn't even be able to click on the tab.

I haven't found out how to avoid that.

this is a really big pain for something simple--but it seems that most of
the control included are lacking in very bacic features and require lots of
extra coding to just do standard things.

I hope you find an answer--I would also like to know.

Shane
"KMiller" <an*******@discussions.microsoft.com> wrote in message
news:00****************************@phx.gbl...
At the time the form is assembled, I DO NOT know.
However, shortly thereafter (during the loading process),
I DO know whether they have access or not to the
particular tab. It's at this time when I'm attempting to
disable (gray-out) the tab text, but nothing works.

I've tried setting the enabled property to false for the
tab, but doing that does nothing to the tab text display,
and users have no way of knowing they DO NOT have access
to the tab other then by clicking into it and finding out
that nothing works because all the controls have been
disabled. Leaving the functionality this way is
inadequate and out of spec.

-----Original Message-----
I assume you don't know before loading the form which to

enable/disable? If
so a contructor passed a tabindex would work fine.

I also assume that you have tried setting the enabled

property for the
particular tab page that you want disabled...

Is this true?

Shane
"KMiller" <an*******@discussions.microsoft.com> wrote in

message
news:05****************************@phx.gbl...
I would like to control entry into one or more of the tabs > I have set up on my Tab control based on set rules. Does > anyone know how to grey-out the text so that a user will > see that they do not have access to that particular tab? >
> I tried setting the enabled = false for the given tab,
but
> it only seems to work in the form assembly section (that > is, if I do it after the form is loaded through a
> function, it doesn't seem to work), and doing that
> disables the controls on the tab, but does not grey out > the text of the tab display itself.
>
> Thanks
>
> K

.

Nov 20 '05 #4

P: n/a
You'll have to OwnerDraw the Tabs if that's the appearance you want.
Why not simply remove the Tabpages that the user has no access to?

"KMiller" <an*******@discussions.microsoft.com> wrote in message
news:00****************************@phx.gbl...
At the time the form is assembled, I DO NOT know.
However, shortly thereafter (during the loading process),
I DO know whether they have access or not to the
particular tab. It's at this time when I'm attempting to
disable (gray-out) the tab text, but nothing works.

I've tried setting the enabled property to false for the
tab, but doing that does nothing to the tab text display,
and users have no way of knowing they DO NOT have access
to the tab other then by clicking into it and finding out
that nothing works because all the controls have been
disabled. Leaving the functionality this way is
inadequate and out of spec.

-----Original Message-----
I assume you don't know before loading the form which to

enable/disable? If
so a contructor passed a tabindex would work fine.

I also assume that you have tried setting the enabled

property for the
particular tab page that you want disabled...

Is this true?

Shane
"KMiller" <an*******@discussions.microsoft.com> wrote in

message
news:05****************************@phx.gbl...
I would like to control entry into one or more of the tabs > I have set up on my Tab control based on set rules. Does > anyone know how to grey-out the text so that a user will > see that they do not have access to that particular tab? >
> I tried setting the enabled = false for the given tab,
but
> it only seems to work in the form assembly section (that > is, if I do it after the form is loaded through a
> function, it doesn't seem to work), and doing that
> disables the controls on the tab, but does not grey out > the text of the tab display itself.
>
> Thanks
>
> K

.

Nov 20 '05 #5

P: n/a
Mick,

I told her the same thing, but how do you draw them with the normal 3d
enabled look?

I tried drawstring using a layout rect and then offset(1,1) or offset(2,2)
on it and drew again using the same with a different color but it doesn't
work.

Also,
disabled means you shouldn't even be able to select the tab in the first
place. How can this be accomplished?

Thanks,

Shane

"Mick Doherty"
<EX***********@AND.REMOVE.SQUAREBRACKETS.[mdaudi100#ntlworld.com]> wrote in
message news:ua*************@TK2MSFTNGP11.phx.gbl...
You'll have to OwnerDraw the Tabs if that's the appearance you want.
Why not simply remove the Tabpages that the user has no access to?

"KMiller" <an*******@discussions.microsoft.com> wrote in message
news:00****************************@phx.gbl...
At the time the form is assembled, I DO NOT know.
However, shortly thereafter (during the loading process),
I DO know whether they have access or not to the
particular tab. It's at this time when I'm attempting to
disable (gray-out) the tab text, but nothing works.

I've tried setting the enabled property to false for the
tab, but doing that does nothing to the tab text display,
and users have no way of knowing they DO NOT have access
to the tab other then by clicking into it and finding out
that nothing works because all the controls have been
disabled. Leaving the functionality this way is
inadequate and out of spec.

-----Original Message-----
I assume you don't know before loading the form which to

enable/disable? If
so a contructor passed a tabindex would work fine.

I also assume that you have tried setting the enabled

property for the
particular tab page that you want disabled...

Is this true?

Shane
"KMiller" <an*******@discussions.microsoft.com> wrote in

message
news:05****************************@phx.gbl...
> I would like to control entry into one or more of the

tabs
> > I have set up on my Tab control based on set rules.

Does
> > anyone know how to grey-out the text so that a user

will
> > see that they do not have access to that particular

tab?
> >
> > I tried setting the enabled = false for the given tab,
> but
> > it only seems to work in the form assembly section

(that
> > is, if I do it after the form is loaded through a
> > function, it doesn't seem to work), and doing that
> > disables the controls on the tab, but does not grey

out
> > the text of the tab display itself.
> >
> > Thanks
> >
> > K
>
.


Nov 20 '05 #6

P: n/a
Thanks for the responses to all..

Seems like a lot of trouble to execute a very simple
change. We purchases the Infragistics UltraDev suite a
while back, which includes a tab control, but we had not
been using it. I just checked it out and sure enough, it
grays-out the text by simply disabling the tab. I may
just swap out by MS tab for this one.

K
-----Original Message-----
Hi K,

wow, I see your point.

I thought I had it fixed in my app too but my titles aren't disabled either.
You can do ownerdrawn fixed and change the color of the font easy enough.
Private Sub TabControl1_DrawItem(ByVal sender As Object, ByVal e AsSystem.Windows.Forms.DrawItemEventArgs) Handles TabControl1.DrawItem Dim tp As TabPage
Dim layoutrct As New RectangleF(e.Bounds.Left, e.Bounds.Top,e.Bounds.Width, e.Bounds.Height)
Dim sf As New StringFormat (StringFormatFlags.FitBlackBox) sf.Alignment = StringAlignment.Center
sf.LineAlignment = StringAlignment.Center

tp = TabControl1.TabPages(e.Index)
If Not tp.Enabled Then
'for some reason not printing the 3-d part--tried to print twicewith offset but no luck
e.Graphics.DrawString(tp.Text, e.Font, SystemBrushes.ControlLight,layoutrct)
layoutrct.Offset(2, 2)
e.Graphics.DrawString(tp.Text, e.Font, SystemBrushes.ControlDark,layoutrct) 'SolidBrush(e.BackColor), layoutrct)
Else
e.Graphics.DrawString(tp.Text, e.Font,New SolidBrush(e.BackColor),layoutrct)
End If
End Sub

This works if items are not enabled. But there must be an easier way--alsothey shouldn't even be able to click on the tab.

I haven't found out how to avoid that.

this is a really big pain for something simple--but it seems that most ofthe control included are lacking in very bacic features and require lots ofextra coding to just do standard things.

I hope you find an answer--I would also like to know.

Shane
"KMiller" <an*******@discussions.microsoft.com> wrote in messagenews:00****************************@phx.gbl...
At the time the form is assembled, I DO NOT know.
However, shortly thereafter (during the loading process), I DO know whether they have access or not to the
particular tab. It's at this time when I'm attempting to disable (gray-out) the tab text, but nothing works.

I've tried setting the enabled property to false for the
tab, but doing that does nothing to the tab text display, and users have no way of knowing they DO NOT have access
to the tab other then by clicking into it and finding out that nothing works because all the controls have been
disabled. Leaving the functionality this way is
inadequate and out of spec.

>-----Original Message-----
>I assume you don't know before loading the form which to
enable/disable? If
>so a contructor passed a tabindex would work fine.
>
>I also assume that you have tried setting the enabled

property for the
>particular tab page that you want disabled...
>
>Is this true?
>
>Shane
>"KMiller" <an*******@discussions.microsoft.com> wrote
in message
>news:05****************************@phx.gbl...
>> I would like to control entry into one or more of the

tabs
>> > I have set up on my Tab control based on set rules.

Does
>> > anyone know how to grey-out the text so that a user

will
>> > see that they do not have access to that particular

tab?
>> >
>> > I tried setting the enabled = false for the given

tab, >> but
>> > it only seems to work in the form assembly section

(that
>> > is, if I do it after the form is loaded through a
>> > function, it doesn't seem to work), and doing that
>> > disables the controls on the tab, but does not grey

out
>> > the text of the tab display itself.
>> >
>> > Thanks
>> >
>> > K
>>
>
>
>.
>

.

Nov 20 '05 #7

P: n/a
Your reply was close. Use ControlPaint.DrawStringDisabled() not
Graphics.DrawString() twice.
As for not being able to select Disabled Tabpages, that can be emulated,
although I feel it is better to remove the TabPage than display it as
Disabled.

Code follows:

\\\
Private ValidPageIndex As Integer = 0

Private Sub TabControl1_DrawItem(ByVal sender As Object, _
ByVal e As System.Windows.Forms.DrawItemEventArgs) _
Handles TabControl1.DrawItem

Dim CurrentTabPage As TabPage = TabControl1.TabPages(e.Index)
Dim r As RectangleF = RectangleF.op_Implicit(e.Bounds)
Dim ItemBrush As New SolidBrush(TabControl1.BackColor)
Dim TextBrush As New SolidBrush(TabControl1.ForeColor)
Dim sf As New StringFormat

sf.Alignment = StringAlignment.Center
sf.LineAlignment = StringAlignment.Center

e.Graphics.FillRectangle(ItemBrush, e.Bounds)

If CurrentTabPage.Enabled = False Then
ControlPaint.DrawStringDisabled(e.Graphics, _
CurrentTabPage.Text, _
e.Font, _
ItemBrush.Color, _
r, sf)
Else
e.Graphics.DrawString(CurrentTabPage.Text, _
e.Font, _
TextBrush, _
r, sf)
End If

End Sub

Private Sub TabControl1_SelectedIndexChanged(ByVal sender As Object, _
ByVal e As System.EventArgs) _
Handles TabControl1.SelectedIndexChanged

If TabControl1.SelectedTab.Enabled = False Then
TabControl1.SelectedIndex = ValidPageIndex
Else
ValidPageIndex = TabControl1.SelectedIndex
End If
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
TabPage2.Enabled = False
End Sub
///

"SStory" <Th*******@TAKEOUTTHISSPAMBUSTERsofthome.net> wrote in message
news:uZ**************@TK2MSFTNGP12.phx.gbl...
Mick,

I told her the same thing, but how do you draw them with the normal 3d
enabled look?

I tried drawstring using a layout rect and then offset(1,1) or offset(2,2)
on it and drew again using the same with a different color but it doesn't
work.

Also,
disabled means you shouldn't even be able to select the tab in the first
place. How can this be accomplished?

Thanks,

Shane

Nov 20 '05 #8

P: n/a
cool, never have noticed that method.

This should have been implemented in the control to begin with.

Thanks,

Shane

"Mick Doherty"
<EX***********@AND.REMOVE.SQUAREBRACKETS.[mdaudi100#ntlworld.com]> wrote in
message news:eg****************@tk2msftngp13.phx.gbl...
Your reply was close. Use ControlPaint.DrawStringDisabled() not
Graphics.DrawString() twice.
As for not being able to select Disabled Tabpages, that can be emulated,
although I feel it is better to remove the TabPage than display it as
Disabled.

Code follows:

\\\
Private ValidPageIndex As Integer = 0

Private Sub TabControl1_DrawItem(ByVal sender As Object, _
ByVal e As System.Windows.Forms.DrawItemEventArgs) _
Handles TabControl1.DrawItem

Dim CurrentTabPage As TabPage = TabControl1.TabPages(e.Index)
Dim r As RectangleF = RectangleF.op_Implicit(e.Bounds)
Dim ItemBrush As New SolidBrush(TabControl1.BackColor)
Dim TextBrush As New SolidBrush(TabControl1.ForeColor)
Dim sf As New StringFormat

sf.Alignment = StringAlignment.Center
sf.LineAlignment = StringAlignment.Center

e.Graphics.FillRectangle(ItemBrush, e.Bounds)

If CurrentTabPage.Enabled = False Then
ControlPaint.DrawStringDisabled(e.Graphics, _
CurrentTabPage.Text, _
e.Font, _
ItemBrush.Color, _
r, sf)
Else
e.Graphics.DrawString(CurrentTabPage.Text, _
e.Font, _
TextBrush, _
r, sf)
End If

End Sub

Private Sub TabControl1_SelectedIndexChanged(ByVal sender As Object, _
ByVal e As System.EventArgs) _
Handles TabControl1.SelectedIndexChanged

If TabControl1.SelectedTab.Enabled = False Then
TabControl1.SelectedIndex = ValidPageIndex
Else
ValidPageIndex = TabControl1.SelectedIndex
End If
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
TabPage2.Enabled = False
End Sub
///

"SStory" <Th*******@TAKEOUTTHISSPAMBUSTERsofthome.net> wrote in message
news:uZ**************@TK2MSFTNGP12.phx.gbl...
Mick,

I told her the same thing, but how do you draw them with the normal 3d
enabled look?

I tried drawstring using a layout rect and then offset(1,1) or offset(2,2) on it and drew again using the same with a different color but it doesn't work.

Also,
disabled means you shouldn't even be able to select the tab in the first
place. How can this be accomplished?

Thanks,

Shane


Nov 20 '05 #9

P: n/a
That or you could try to make your own control inheriting from the tab
control, "K's Tab Control"

Just add that functionality and display some interface for disabling
tabs....

You're right it's a pain and like most things I've found in .net, is a
standard expectation that should have been implemented in the original
control. (guess they want to make sure you go with 3rd part vendors and not
put them out of business or something.) Still there is lots of room for 3rd
party controls and I agree with you that things like this are just bare
minimum expected behaviors.

Removing the tab does seem to be a lot easier. I suggest that route unless
you want to make your own reusuable control--which shouldn't be too hard....
;) maybe.

Shane
"KMiller" <an*******@discussions.microsoft.com> wrote in message
news:01****************************@phx.gbl...
Thanks for the responses to all..

Seems like a lot of trouble to execute a very simple
change. We purchases the Infragistics UltraDev suite a
while back, which includes a tab control, but we had not
been using it. I just checked it out and sure enough, it
grays-out the text by simply disabling the tab. I may
just swap out by MS tab for this one.

K
-----Original Message-----
Hi K,

wow, I see your point.

I thought I had it fixed in my app too but my titles

aren't disabled either.

You can do ownerdrawn fixed and change the color of the

font easy enough.

Private Sub TabControl1_DrawItem(ByVal sender As Object,

ByVal e As
System.Windows.Forms.DrawItemEventArgs) Handles

TabControl1.DrawItem
Dim tp As TabPage
Dim layoutrct As New RectangleF(e.Bounds.Left,

e.Bounds.Top,
e.Bounds.Width, e.Bounds.Height)
Dim sf As New StringFormat

(StringFormatFlags.FitBlackBox)
sf.Alignment = StringAlignment.Center
sf.LineAlignment = StringAlignment.Center

tp = TabControl1.TabPages(e.Index)
If Not tp.Enabled Then
'for some reason not printing the 3-d part--tried

to print twice
with offset but no luck
e.Graphics.DrawString(tp.Text, e.Font,

SystemBrushes.ControlLight,
layoutrct)
layoutrct.Offset(2, 2)
e.Graphics.DrawString(tp.Text, e.Font,

SystemBrushes.ControlDark,
layoutrct) 'SolidBrush(e.BackColor), layoutrct)
Else
e.Graphics.DrawString(tp.Text, e.Font,New

SolidBrush(e.BackColor),
layoutrct)
End If
End Sub

This works if items are not enabled. But there must be

an easier way--also
they shouldn't even be able to click on the tab.

I haven't found out how to avoid that.

this is a really big pain for something simple--but it

seems that most of
the control included are lacking in very bacic features

and require lots of
extra coding to just do standard things.

I hope you find an answer--I would also like to know.

Shane
"KMiller" <an*******@discussions.microsoft.com> wrote in

message
news:00****************************@phx.gbl...
At the time the form is assembled, I DO NOT know.
However, shortly thereafter (during the loading process), I DO know whether they have access or not to the
particular tab. It's at this time when I'm attempting to disable (gray-out) the tab text, but nothing works.

I've tried setting the enabled property to false for the
tab, but doing that does nothing to the tab text display, and users have no way of knowing they DO NOT have access
to the tab other then by clicking into it and finding out that nothing works because all the controls have been
disabled. Leaving the functionality this way is
inadequate and out of spec.
>-----Original Message-----
>I assume you don't know before loading the form which to enable/disable? If
>so a contructor passed a tabindex would work fine.
>
>I also assume that you have tried setting the enabled
property for the
>particular tab page that you want disabled...
>
>Is this true?
>
>Shane
>"KMiller" <an*******@discussions.microsoft.com> wrote in message
>news:05****************************@phx.gbl...
>> I would like to control entry into one or more of the
tabs
>> > I have set up on my Tab control based on set rules.
Does
>> > anyone know how to grey-out the text so that a user
will
>> > see that they do not have access to that particular
tab?
>> >
>> > I tried setting the enabled = false for the given tab, >> but
>> > it only seems to work in the form assembly section
(that
>> > is, if I do it after the form is loaded through a
>> > function, it doesn't seem to work), and doing that
>> > disables the controls on the tab, but does not grey
out
>> > the text of the tab display itself.
>> >
>> > Thanks
>> >
>> > K
>>
>
>
>.
>

.

Nov 20 '05 #10

P: n/a
> Removing the tab does seem to be a lot easier. I suggest that route
unless
you want to make your own reusuable control--which shouldn't be too hard.... ;) maybe.

Much harder than you'd think. I'm currently working on a new TabControl and
you wouldn't believe the amount of problems I'm coming up against, but it is
coming along.
Nov 20 '05 #11

P: n/a
A certain axiom comes to mind involving wheels and re-
invention ;}

-----Original Message-----
Removing the tab does seem to be a lot easier. I
suggest that routeunless
you want to make your own reusuable control--which
shouldn't be toohard....
;) maybe.
Much harder than you'd think. I'm currently working on a

new TabControl andyou wouldn't believe the amount of problems I'm coming up against, but it iscoming along.
.

Nov 20 '05 #12

P: n/a
Not re-inventing - but remodelling.

"KMiller" <an*******@discussions.microsoft.com> wrote in message
news:0b****************************@phx.gbl...
A certain axiom comes to mind involving wheels and re-
invention ;}

-----Original Message-----
Removing the tab does seem to be a lot easier. I

suggest that route
unless
you want to make your own reusuable control--which

shouldn't be too
hard....
;) maybe.

Much harder than you'd think. I'm currently working on a

new TabControl and
you wouldn't believe the amount of problems I'm coming up

against, but it is
coming along.
.

Nov 20 '05 #13

P: n/a
Wow!

I guess the point is that we shouldn't have to do it in the first place.
That should have been included in any standard tab control I would think.
"Mick Doherty"
<EX***********@AND.REMOVE.SQUAREBRACKETS.[mdaudi100#ntlworld.com]> wrote in
message news:OF**************@TK2MSFTNGP11.phx.gbl...
Not re-inventing - but remodelling.

"KMiller" <an*******@discussions.microsoft.com> wrote in message
news:0b****************************@phx.gbl...
A certain axiom comes to mind involving wheels and re-
invention ;}

-----Original Message-----
> Removing the tab does seem to be a lot easier. I

suggest that route
unless
> you want to make your own reusuable control--which

shouldn't be too
hard....
> ;) maybe.
>
Much harder than you'd think. I'm currently working on a

new TabControl and
you wouldn't believe the amount of problems I'm coming up

against, but it is
coming along.
.


Nov 20 '05 #14

This discussion thread is closed

Replies have been disabled for this discussion.