更改选项卡控件的背景颜色

时间:2017-08-26 15:17:14

标签: c# winforms background-color tabcontrol

我将如何更改tabcontrol的全部背景颜色(ownerdrawfixed / flatbutton外观)?不只是顶部,而是整个背景?我正在使用C#WinForms。

 Font fntTab;
        Brush bshBack;
        Brush bshFore;

        if (e.Index == this.tabControl1.SelectedIndex)
        {
            fntTab = new Font(e.Font, FontStyle.Bold);
            bshBack = new System.Drawing.Drawing2D.LinearGradientBrush(e.Bounds, SystemColors.ScrollBar, SystemColors.ScrollBar, System.Drawing.Drawing2D.LinearGradientMode.BackwardDiagonal);
            bshFore = Brushes.Black;
            //bshBack = new System.Drawing.Drawing2D.LinearGradientBrush(e.Bounds, Color.LightSkyBlue , Color.LightGreen, System.Drawing.Drawing2D.LinearGradientMode.BackwardDiagonal);
            //bshFore = Brushes.Blue;
        }
        else
        {
            fntTab = e.Font;
            bshBack = new SolidBrush(Color.Red);
            bshFore = new SolidBrush(Color.Aqua);

            //bshBack = new SolidBrush(Color.White);
            //bshFore = new SolidBrush(Color.Black);
        }

        string tabName = this.tabControl1.TabPages[e.Index].Text;
        StringFormat sftTab = new StringFormat();
        e.Graphics.FillRectangle(bshBack, e.Bounds);
        Rectangle recTab = e.Bounds;
        recTab = new Rectangle(recTab.X, recTab.Y + 4, recTab.Width, recTab.Height - 4);
        e.Graphics.DrawString(tabName, fntTab, bshFore, recTab, sftTab);

1 个答案:

答案 0 :(得分:0)

我认为你必须使用this.tabControl1.BackColor