2017-08-26 98 views
0

我该如何去改变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

使用WPF也许是...不,认真,看到这个:https://www.codeproject.com/Articles/91387/Painting-Your-Own-Tabs-Second-Edition – z3nth10n

回答

0

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