I have a TabControl
with five Tabs and DrawMode
set to OwnerDrawFixed
. What I actually try to do is to change the font color of the last tab header from black to blue. The following code that handles the DrawItem
-Event works fine and shows the also following tabs:
Code:
private void tabControl_DrawItem(object sender, DrawItemEventArgs e)
{
if (e.Index == 4)
{
e.Graphics.DrawString("Notifications", new Font(tabControl.Font, FontStyle.Bold), new SolidBrush(SystemColors.HotTrack), new PointF(e.Bounds.X + 2, e.Bounds.Y + 3));
}
else
{
e.Graphics.DrawString(tabControl.TabPages[e.Index].Text, tabControl.Font, Brushes.Black, new PointF(e.Bounds.X + 5, e.Bounds.Y + 3));
}
}
GUI:
As soon as I click on one of the tabs, the header font itself changes a bit, it becomes a bit "thicker". I don't really know how to describe it, so here's a picture:
What I did here was clicking the first three tabs. I already know that it's because of the DrawItem
-Event that paints over the already existing font.
So my question now is: Can I "reset" the tab header's font inside the handler so the font isn't painted over every time and becomes thicker when the event is fired?
I already tried using e.Graphics.Clear()
(because I thought it would just "clear" the header), however this doesn't show the header title afterwards when I draw it using e.Graphics.DrawString()
.
Does anyone have an idea how to bypass this "process of overpainting"?
EDIT:
I figured out that the behavior only occurs when you set the TabControl
's property Appearance
to Buttons
, as I did. The other values do not make the behavior occur.
So is there any possibility to bypass this when the Appearance
property is set to Buttons
?