2016-02-23 97 views

回答

0

DrawItemEventArgs e參數會告訴你所有你需要的。

要繪製療法頭在各種顏色由myBrush更換Brushes.Black並把DrawString這樣的使用條款中:

using (SolidBrush myBrush = new SolidBrush (tabControl1.TabPages[e.Index].ForeColor)) 
{ 
    e.Graphics.DrawString(tabControl1.TabPages[e.Index].Text, e.Font, myBrush , 
          e.Bounds.Left + (e.Bounds.Width - sz.Width)/2, 
          e.Bounds.Top + (e.Bounds.Height - sz.Height)/2 + 1); 
} 

現在每頭將在其TabPageForeColor繪製。

TextRenderer.DrawText代替DrawString會更好!

如果你只是想改變選擇標籤的顏色簡單地使用這樣的檢查:

SolidBrush myBrush = new SolidBrush (e.State.HasFlag(DrawItemState.Selected) ? 
        SystemColors.ActiveCaptionText : SystemColors.ControlText) 
+0

的感謝!我意識到該方法是在tabcontrol中的每個選項卡中調用的。我認爲這只是要求所選標籤。現在它是有道理的。非常感謝 – minimouse