Reputation: 1776
I have some tabControl in C# Windows app. It has some tabPages. Does anyone kwows how to make the tabPage Text to become Bold..?
Upvotes: 6
Views: 19201
Reputation: 1
All one has to do is write the main TabControl code as follows:
TabControl0_1=New TabControl
TabControl0_1.Size = New System.Drawing.Size(1900,980)
TabControl0_1.Location=New System.Drawing.Point(5,5)
TabControl0_1.Font = New System.Drawing.Font("Segoe UI",25!, _
System.Drawing.FontStyle.Bold, System.Drawing. _
GraphicsUnit.Point,CType(0, Byte))
This takes care of everything. There are total 114 TabPages.
Upvotes: 0
Reputation: 4582
Another, less elegant option is to set the font->bold property of the parent form/control to true, which will make everything bold including the tab names and then set bold to false on all the controls you don't want bold.
Upvotes: 0
Reputation: 1776
You'll need to handle the DrawItem
event of the TabControl
to manually draw the caption. Note: DrawMode
of affected control should be set to TabDrawMode.OwnerDrawFixed
.
Here is a sample:
private void tabControl1_DrawItem(object sender, DrawItemEventArgs e)
{
Graphics g = e.Graphics;
Brush _TextBrush;
// Get the item from the collection.
TabPage _TabPage = tabControl1.TabPages[e.Index];
// Get the real bounds for the tab rectangle.
Rectangle _TabBounds = tabControl1.GetTabRect(e.Index);
if (e.State == DrawItemState.Selected)
{
// Draw a different background color, and don't paint a focus rectangle.
_TextBrush = new SolidBrush(Color.Blue);
g.FillRectangle(Brushes.Gray, e.Bounds);
}
else
{
_TextBrush = new System.Drawing.SolidBrush(e.ForeColor);
// e.DrawBackground();
}
// Use our own font. Because we CAN.
Font _TabFont = new Font(e.Font.FontFamily, (float)9, FontStyle.Bold, GraphicsUnit.Pixel);
//Font fnt = new Font(e.Font.FontFamily, (float)7.5, FontStyle.Bold);
// Draw string. Center the text.
StringFormat _StringFlags = new StringFormat();
_StringFlags.Alignment = StringAlignment.Center;
_StringFlags.LineAlignment = StringAlignment.Center;
g.DrawString(tabControl1.TabPages[e.Index].Text, _TabFont, _TextBrush,
_TabBounds, new StringFormat(_StringFlags));
}
Upvotes: 13
Reputation: 45101
In Winforms you can change the DrawMode and paint all the captions on yourself.
See the MSDN Example.
Upvotes: 3