Winforms C#Winform:如何设置TabControl(而不是tabpage)的基本颜色

Winforms C#Winform:如何设置TabControl(而不是tabpage)的基本颜色,winforms,Winforms,这似乎是一个简单的问题,但如何设置“选项卡控件”的背景颜色,它似乎是从标准窗口主题颜色派生出来的。是否可以创建一个黑色选项卡控件,在选项卡本身(而不是选项卡页面)上写入白色文本 帮助,我对扩展现有控件的自定义控件有点熟悉,但我不知道要设置哪些属性(如果存在)。 我在mu-TabControl派生类中使用了类似的东西(它也会做渐变): 受保护的覆盖无效OnDrawItem(DrawItemEventArgs e) { //填空 使用(SolidBrush br=新的SolidBrush(Theme

这似乎是一个简单的问题,但如何设置“选项卡控件”的背景颜色,它似乎是从标准窗口主题颜色派生出来的。是否可以创建一个黑色选项卡控件,在选项卡本身(而不是选项卡页面)上写入白色文本

帮助,我对扩展现有控件的自定义控件有点熟悉,但我不知道要设置哪些属性(如果存在)。


我在mu-TabControl派生类中使用了类似的东西(它也会做渐变):

受保护的覆盖无效OnDrawItem(DrawItemEventArgs e)
{
//填空
使用(SolidBrush br=新的SolidBrush(Theme.FormBackColor))
{
e、 图形填充矩形(br,ClientRectangle);
}
//画标签
对于(int i=0;i
private void tabControl1_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)
{
TabPage CurrentTab = tabControl1.TabPages[e.Index];
Rectangle ItemRect = tabControl1.GetTabRect(e.Index);
SolidBrush FillBrush = new SolidBrush(Color.Red);
SolidBrush TextBrush = new SolidBrush(Color.White);
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.White;
    TextBrush.Color = Color.Red;
    ItemRect.Inflate(2, 2);
}

//Set up rotation for left and right aligned tabs
if (tabControl1.Alignment == TabAlignment.Left || tabControl1.Alignment == TabAlignment.Right)
{
    float RotateAngle = 90;
    if (tabControl1.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();
}
protected override void OnDrawItem(DrawItemEventArgs e)
{
    // fill in the whole rect
    using (SolidBrush br = new SolidBrush(Theme.FormBackColor))
    {
        e.Graphics.FillRectangle(br, ClientRectangle);
    }

    // draw the tabs
    for (int i = 0; i < TabPages.Count; ++i)
    {
        TabPage tab = TabPages[i];
        // Get the text area of the current tab
        RectangleF tabTextArea = (RectangleF)GetTabRect(i);

        // determine how to draw the tab based on which type of tab it is
        Color tabTopBackColor = GetTopBackColor();
        Color tabBottomBackColor = GetBottomBackColor();
        Color tabTextColor = GetTextColor();

        // draw the background
        using (LinearGradientBrush br = new LinearGradientBrush(tabTextArea, tabTopBackColor, tabBottomBackColor, LinearGradientMode.Vertical))
        {
            e.Graphics.FillRectangle(br, tabTextArea);
        }

        // draw the tab header text
        using (SolidBrush brush = new SolidBrush(tabTextColor))
        {
            e.Graphics.DrawString(tab.Text, Font, brush, CreateTabHeaderTextRect(tabTextArea));
        }
    }
}

private RectangleF CreateTabHeaderTextRect(RectangleF tabTextArea)
{
    tabTextArea.X += 3;
    tabTextArea.Y += 1;

    tabTextArea.Height -= 1;

    return tabTextArea;
}