Windows 窗体:如何更改禁用标签的字体颜色 [英] Windows Forms: How do you change the font color for a disabled label

查看:42
本文介绍了Windows 窗体:如何更改禁用标签的字体颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为标签控件设置禁用的字体特征.我可以设置所有字体特征(大小、粗体等),但颜色被默认窗口行为覆盖,该行为似乎是这两种颜色之一:

I am trying to set the disabled font characteristics for a Label Control. I can set all of the Font characteristics (size, bold, etc), but the color is overridden by the default windows behavior which seems to be one of these two colors:

  • 如果背景颜色是透明的,则前景色与禁用文本框的颜色相同.
  • 如果背景颜色设置为其他颜色,则前景色为深灰色.

下图展示了行为——第 1 列是标签,第 2 列是文本框,第 3 列是组合框.

The image below demonstrates the behavior -- Column 1 is Labels, Column 2 is TextBoxs, and Column 3 is ComboBoxes.

编辑——解释图像:前两行是标签、文本框和组合框的默认样式.在后两行中,我将背景颜色设置为红色,将前景设置为白色.Microsoft 禁用的字体样式处理不一致.

Edit -- Explaining the image: The first two rows are default styles for a label, textbox, and combobox. In the second two rows, I set the Background color to Red and Foreground to White. The disabled font style handling by Microsoft is inconsistent.

推荐答案

查看ControlPaint.DrawStringDisabled 方法;它可能会有所帮助.我在覆盖自定义控件的 OnPaint 事件时使用了它.

Take a look at the ControlPaint.DrawStringDisabled method; it might be something helpful. I've used it when overriding the OnPaint event for custom controls.

ControlPaint.DrawStringDisabled(g, this.Text, this.Font, Color.Transparent,
                new Rectangle(CustomStringWidth, 5, StringSize2.Width, StringSize2.Height), StringFormat.GenericTypographic);

这篇关于Windows 窗体:如何更改禁用标签的字体颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆