Tab Pages text help

  • Thread starter Thread starter NewGuy
  • Start date Start date
N

NewGuy

Is there a way to change the Text format for just the Tab Title?

I have a form with 3 tabs on it
[Tab One][Tab Two][Tab Three]

If conditions are met I would like to modify the text on the tab it'sself so
the user knows there is something there
For example I would like the text [Tab One] to be bold... I can't find a
way to do this.
 
Hi NewGuy,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need the text in tabcontrol to be
bold. If there is any misunderstanding, please feel free to let me know.

Searching in google, there are many people doing the same thing. First, we
set DrawMode property of the TabControl to OwnerDrawFixed. Then, we handle
the DrawItem event to draw our own text with particular fonts. Here is an
example:

private void tabControl1_DrawItem(object sender,
System.Windows.Forms.DrawItemEventArgs e)
{
Font tabFont = e.Font;
Brush backGroundBrush = new SolidBrush(SystemColors.Control);
Brush foreGroundBrush = new SolidBrush(SystemColors.WindowText);

TabControl aTabControl = (TabControl) sender;
TabPage tabPage = aTabControl.TabPages[e.Index];
string tabName = aTabControl.TabPages[e.Index].Text;

StringFormat tabStringFormat = new StringFormat();

Rectangle tabRectangle = new Rectangle(
e.Bounds.X
, e.Bounds.Y + 4
, e.Bounds.Width + 4
, e.Bounds.Height);

if ( e.Index == aTabControl.SelectedIndex)
{
tabFont = new Font(tabFont, FontStyle.Bold);
}

//Paint Tab Background
e.Graphics.FillRectangle(backGroundBrush, e.Bounds);
//Draw Tab Text
e.Graphics.DrawString(tabName, tabFont, foreGroundBrush, tabRectangle,
tabStringFormat);
}

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
Back
Top