0

How would I go about to change the full background color of a tabcontrol (ownerdrawfixed / flatbutton appearance)? Not just the top part, but the whole background? I'm using 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
    Using WPF maybe yes... No, seriously, see this: https://www.codeproject.com/Articles/91387/Painting-Your-Own-Tabs-Second-Edition – z3nth10n Aug 26 '17 at 15:21

1 Answers1

0

I think you have to use this.tabControl1.BackColor.

AlexL
  • 25
  • 5