I have to change the BackColor of a TabControl.
therefore I have overriden the onPaint-Method of TabControl like this:
Rectangle rectangle = new Rectangle(0, 0, this.Width, this.Height);
SolidBrush brush = new SolidBrush(Color.YellowGreen);
e.Graphics.FillRectangle(brush, rectangle);
the problem is now, that the tabs in my TabControl are not visible anymore,
because they have also the color YellowGreen.
How can I make the tabs of my TabControl visible or how can I change their
color?
does anybody have some experience with that kind of problem?
Any help will be greatly appreciated....
Most folks shy away from painting their own control and typically get a tab
control that supports this from a 3rd party vendor. However to answer your
question just override the paint event for the individual tab page. I
tested it quickly and it worked without any problems.
Rectangle rectangle = new Rectangle(0, 0, tabPage1.Width,
tabPage1.Height);
SolidBrush brush = new SolidBrush(Color.YellowGreen);
e.Graphics.FillRectangle(brush, rectangle);
Of course by painting the tabpage the actual tabs don't change color so
you'll have to change those to be ownerdrawn. You can draw those with
something simple like:
private void tabControl1_DrawItem(object sender,
System.Windows.Forms.DrawItemEventArgs e)
{
Graphics g = e.Graphics;
Rectangle myTabRect = tabControl1.GetTabRect(0);
SolidBrush b = new SolidBrush(Color.Blue);
g.FillRectangle(b, myTabRect);
}
Thanks! Robert Gruen - http://blogs.msdn.com/robgruen
Microsoft, VB.NET
This posting is provided "AS IS", with no warranties, and confers no rights.
--------------------
#From: "Paiam Salavati" <paiam.salavati@skillworks.de>
#Newsgroups: microsoft.public.dotnet.framework.windowsforms.designtime
#Subject: changing backcolor of tabcontrol
#Date: Tue, 25 May 2004 09:51:37 +0200
#Lines: 24
#Message-ID: <2hgc80Fcifa8U1@uni-berlin.de>
#X-Trace: news.uni-berlin.de
tKqso5pc+prHKrikLU4blwib8p4LObxgimBBOJlpbNJJwgGcET
#X-Priority: 3
#X-MSMail-Priority: Normal
#X-Newsreader: Microsoft Outlook Express 6.00.2800.1409
#X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409
#Path:
cpmsftngxa10.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfeed00.s
ul.t-online.de!t-online.de!newsfeed.freenet.de!fu-berlin.de!uni-berlin.de!no
t-for-mail
#Xref: cpmsftngxa10.phx.gbl
microsoft.public.dotnet.framework.windowsforms.designtime:4681
#X-Tomcat-NG: microsoft.public.dotnet.framework.windowsforms.designtime
#
#I have to change the BackColor of a TabControl.
#
#therefore I have overriden the onPaint-Method of TabControl like this:
#
#Rectangle rectangle = new Rectangle(0, 0, this.Width, this.Height);
#SolidBrush brush = new SolidBrush(Color.YellowGreen);
#
#e.Graphics.FillRectangle(brush, rectangle);
#
#
#
#
#the problem is now, that the tabs in my TabControl are not visible anymore,
#because they have also the color YellowGreen.
#
#How can I make the tabs of my TabControl visible or how can I change their
#color?
#
#does anybody have some experience with that kind of problem?
#
#Any help will be greatly appreciated....
#
#
#
#
Paiam Salavati - 01 Jun 2004 08:36 GMT
the problem is, that if I want to override the onPaint-method, I have to set
the user-Bite for user-controlled-painting like this:
this.SetStyle(System.Windows.Forms.ControlStyles.UserPaint, true);
If I did so, it seems that the DrawItem-Event will not be fired any more, so
that the tabs of my tabControl won't be visible. They still exist because I
can switch the TabPages, but they have the same color as I set it for my
TabControl.
If I don't set the user-bite in the described way the Color of my TabControl
won't be changed.
I don't know how to solve this problem. Maybe I have to throw the
DrawItem-Event for myself, but where and in which way?
> Most folks shy away from painting their own control and typically get a tab
> control that supports this from a 3rd party vendor. However to answer your
[quoted text clipped - 38 lines]
> #X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409
> #Path:
cpmsftngxa10.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfeed00.s
ul.t-online.de!t-online.de!newsfeed.freenet.de!fu-berlin.de!uni-berlin.de!no
> t-for-mail
> #Xref: cpmsftngxa10.phx.gbl
[quoted text clipped - 26 lines]
> #
> #