473,386 Members | 1,745 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,386 software developers and data experts.

1 tab control, 5 tab pages - different color

I have one tab control with 5 tab pages.
I want to color each tab page a different color.
Does anyone know how to color the entire tab page a unique color?
(that includes the tab part of the tab page)
In other words, just like different paper folders come in different colors,
how do you program this?

If you look at the code I got from Microsoft, this will color only one tab
and put text on only one tab:
HOw does one do it when you have 5 tab pages with one tab control?

tabControl1.DrawMode = TabDrawMode.OwnerDrawFixed;
....
....

tabControl1.DrawItem += new DrawItemEventHandler(DrawOnTab);
....
....
private void DrawOnTab(object sender, DrawItemEventArgs e)
{
Graphics g = e.Graphics;
Pen p = new Pen(Color.Blue);
Font font = new Font("Arial", 10.0f);
SolidBrush brush = new SolidBrush(Color.Red);
SolidBrush brush1 = new
SolidBrush(Color.Beige);
g.DrawRectangle(p, tabArea);
g.DrawString("tabPage1",font,brush,tabTextArea);
}
Nov 17 '05 #1
4 8808
got an ugly one, hope it's helpful:
------------------------------------------------------
private void DrawOnTab(object sender, DrawItemEventArgs e)
{
if (e.State == DrawItemState.Selected)
{
TabControl tc = (TabControl) sender;
TabPage currentTab = tc.TabPages[tc.SelectedIndex];
Graphics g = e.Graphics;
Font font = new Font("Arial", 10.0f);
SolidBrush brushRed = new SolidBrush(Color.Red);
Color[] backColors = new Color[3]{Color.Blue,
Color.Green, Color.Black};
Rectangle tabArea = e.Bounds;
Rectangle tabTextArea = e.Bounds;
Brush backBrush = new
SolidBrush(backColors[tc.SelectedIndex]);
g.FillRectangle(backBrush, tabArea);
currentTab.BackColor = backColors[tc.SelectedIndex];
g.DrawString(currentTab.Text, font, brushRed,
tabTextArea);
}
}

private void tabControl1_SelectedIndexChanged(object sender,
System.EventArgs e)
{
tabControl1.Invalidate();
}

Nov 17 '05 #2
You'll find several tips on modifying TabControl on my site.
http://dotnetrix.co.uk/tabcontrols.html

You'll also find TabControlEX which has already got these features built in.
http://dotnetrix.co.uk/controls.html --> TabControlEX

--
Mick Doherty
http://dotnetrix.co.uk/nothing.html
"Martha" <Ma****@discussions.microsoft.com> wrote in message
news:20**********************************@microsof t.com...
I have one tab control with 5 tab pages.
I want to color each tab page a different color.
Does anyone know how to color the entire tab page a unique color?
(that includes the tab part of the tab page)
In other words, just like different paper folders come in different
colors,
how do you program this?

If you look at the code I got from Microsoft, this will color only one tab
and put text on only one tab:
HOw does one do it when you have 5 tab pages with one tab control?

tabControl1.DrawMode = TabDrawMode.OwnerDrawFixed;
...
...

tabControl1.DrawItem += new DrawItemEventHandler(DrawOnTab);
...
...
private void DrawOnTab(object sender, DrawItemEventArgs e)
{
Graphics g = e.Graphics;
Pen p = new Pen(Color.Blue);
Font font = new Font("Arial", 10.0f);
SolidBrush brush = new SolidBrush(Color.Red);
SolidBrush brush1 = new
SolidBrush(Color.Beige);
g.DrawRectangle(p, tabArea);
g.DrawString("tabPage1",font,brush,tabTextArea);
}

Nov 17 '05 #3
realfun almost has a perfect solution, however the non active tabs turned to
grey color instead of keeping their color. In other words, the only tab that
has the right color is the active tab (one just clicked) Any ideas on how to
fix it?
Martha

"re*****@gmail.com" wrote:
got an ugly one, hope it's helpful:
------------------------------------------------------
private void DrawOnTab(object sender, DrawItemEventArgs e)
{
if (e.State == DrawItemState.Selected)
{
TabControl tc = (TabControl) sender;
TabPage currentTab = tc.TabPages[tc.SelectedIndex];
Graphics g = e.Graphics;
Font font = new Font("Arial", 10.0f);
SolidBrush brushRed = new SolidBrush(Color.Red);
Color[] backColors = new Color[3]{Color.Blue,
Color.Green, Color.Black};
Rectangle tabArea = e.Bounds;
Rectangle tabTextArea = e.Bounds;
Brush backBrush = new
SolidBrush(backColors[tc.SelectedIndex]);
g.FillRectangle(backBrush, tabArea);
currentTab.BackColor = backColors[tc.SelectedIndex];
g.DrawString(currentTab.Text, font, brushRed,
tabTextArea);
}
}

private void tabControl1_SelectedIndexChanged(object sender,
System.EventArgs e)
{
tabControl1.Invalidate();
}

Nov 17 '05 #4
I suggest you follow Mick's link, it solves your problem from lap to
top.

Nov 17 '05 #5

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

Similar topics

1
by: Lars Behrmann | last post by:
Hi, i have an ActiveX control placed on my windowsform. Visual Studio has wrapped this and everything should be fine, but it isn't :( The control shows different behaviours between the Visual...
1
by: Alessandro | last post by:
There is a way to give different color to listitems of a ListBox ?
1
by: TJS | last post by:
I am populating a dropdownlist control from a query. Each line of content in the dropdownlist may get modified with a leading text character as a flag before being added to the list. how can I...
1
by: Mamatha | last post by:
Hi I have one application in VB.NET using the concept of mutithreading.In that application when we click on one button some will be displayed by the threads in the listbox.Actually i downloaded...
1
by: ad | last post by:
I set a row of gridview different color when one value in the first column if greater the the value in the second column. How can I do?
5
by: ad | last post by:
I want to show the background color of a row in a gridview to different color when the value of a column is greater than 100. How can I do?
11
by: bb nicole | last post by:
Below is css for the link color for my homepage... My homepage have 5 different table which contain a link... If i wish to have different color for the link in different table in same page, what...
4
by: Simon | last post by:
By default, days in the calendar control are simply displayed as numbers, I want to show some days in a different color in this control. What is the best way to do that? Thanks very much.
4
by: JB | last post by:
Hi All, I have a DataGridView in which some columns are combo boxes (i.e. DataGridViewComboBoxColumn). I populate these Combo Boxes directly by using code like this: Dim NewCol As New...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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,...

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.