我不想更改标题的背景颜色,我想根据标题背景颜色的深浅程度更改标题中的文本颜色。
即如果标题的背景颜色是黑色或深紫色,则将文本设为白色。或者,如果标题的背景颜色是亮黄色,则将文本设为黑色。
谢谢。
设置标签页的绘制模式:
tabControl1.DrawMode = TabDrawMode.OwnerDrawFixed;
tabControl1.DrawItem += tabControl1_DrawItem;
Run Code Online (Sandbox Code Playgroud)
进而:
private void tabControl1_DrawItem(object sender, DrawItemEventArgs e)
{
e.DrawBackground();
var color = GetDesiredColor(e.Index); // TODO: Implement it for yourself
TextRenderer.DrawText(e.Graphics, tabControl1.TabPages[e.Index].Text, e.Font, e.Bounds, color);
}
Run Code Online (Sandbox Code Playgroud)
当然,您可能也想调整边界。