Change Tabpage title color

Asked

Viewed 894 times

0

Does anyone know how to change the color of the title Tabpage in C#? Not full page text color, only page title color (from Tab).

  • What is the graphical interface technology (GUI)?

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();
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.