【问题标题】:C# WindowsForm - How to change a tabpages headers text color based on how dark the background color is? [duplicate]C# Windows 窗体 - 如何根据背景颜色的深浅来更改标签页标题文本颜色? [复制]
【发布时间】:2017-05-17 16:15:12
【问题描述】:

我不想改变标题的背景颜色,我想根据标题背景颜色的深浅来改变标题中的文本颜色。

即,如果标题的背景颜色是黑色或深紫色,则将文本设置为白色。 或者,如果标题的背景颜色为亮黄色,则将文本变为黑色。

谢谢。

【问题讨论】:

标签: c# winforms colors tabs


【解决方案1】:

设置标签页的绘制模式:

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

然后:

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

当然,您可能也想调整边界。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-06-02
    • 1970-01-01
    • 1970-01-01
    • 2018-09-29
    • 1970-01-01
    • 1970-01-01
    • 2018-07-09
    相关资源
    最近更新 更多