2017-08-26 6 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を使用しなければならないと思います。