Change tab title color

0

Does anyone know how to change the color of the TabPage title in C # ? Not the color of the entire page text, just the page title (of Tab ).

    
asked by anonymous 17.09.2014 / 13:41

1 answer

0

In the Event below, include the following code.

private void TAB_DrawItem(object sender, DrawItemEventArgs e)
{
    TabPage CurrentTab = TAB.TabPages[e.Index];
    Rectangle ItemRect = TAB.GetTabRect(e.Index);
    SolidBrush FillBrush = new SolidBrush(Color.White);
    SolidBrush TextBrush = new SolidBrush(Color.Black);
    StringFormat sf = new StringFormat();
    sf.Alignment = StringAlignment.Center;
    sf.LineAlignment = StringAlignment.Center;

    //If we are currently painting the Selected TabItem we'll
    //change the brush colors and inflate the rectangle.
    if (System.Convert.ToBoolean(e.State & DrawItemState.Selected))
    {
        FillBrush.Color = Color.Red;
        TextBrush.Color = Color.White;
        ItemRect.Inflate(2, 2);
    }

    //Set up rotation for left and right aligned tabs
    if (TAB.Alignment == TabAlignment.Left || TAB.Alignment == TabAlignment.Right)
    {
        float RotateAngle = 90;
        if (TAB.Alignment == TabAlignment.Left)
            RotateAngle = 270;
        PointF cp = new PointF(ItemRect.Left + (ItemRect.Width / 2), ItemRect.Top + (ItemRect.Height / 2));
        e.Graphics.TranslateTransform(cp.X, cp.Y);
        e.Graphics.RotateTransform(RotateAngle);
        ItemRect = new Rectangle(-(ItemRect.Height / 2), -(ItemRect.Width / 2), ItemRect.Height, ItemRect.Width);
    }

    //Next we'll paint the TabItem with our Fill Brush
    e.Graphics.FillRectangle(FillBrush, ItemRect);

    //Now draw the text.
    e.Graphics.DrawString(CurrentTab.Text, e.Font, TextBrush, (RectangleF)ItemRect, sf);


    //Reset any Graphics rotation
    e.Graphics.ResetTransform();

    //Finally, we should Dispose of our brushes.
    FillBrush.Dispose();
    TextBrush.Dispose();
}
    
17.09.2014 / 17:00