5

enter image description here

I do not want to change the background color of the header, I want to change the text color in the header based on how dark or bright the background color of the header is.

I.e if the background color of the header is black or dark purple then make the text white. Or if the background color of the header is bright yellow make the text black.

Thanks.

Floern
  • 33,559
  • 24
  • 104
  • 119
  • Please do not vandalize your posts. By posting on the Stack Exchange network, you've granted a non-revocable right for SE to distribute that content (under the [CC BY-SA 3.0 license](https://creativecommons.org/licenses/by-sa/3.0/)). By SE policy, any vandalism will be reverted. If you would like to disassociate this post from your account, see [What is the proper route for a disassociation request?](https://meta.stackoverflow.com/q/323395) – NobodyNada May 04 '17 at 22:23

1 Answers1

5

Set the draw mode of you tab page:

tabControl1.DrawMode = TabDrawMode.OwnerDrawFixed;
tabControl1.DrawItem += tabControl1_DrawItem;

And then:

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);
}

Of course, you might want to adjust the bounds, too.

György Kőszeg
  • 17,093
  • 6
  • 37
  • 65