如何更改禁用的 TextBox 的字体颜色? [英] How to change the font color of a disabled TextBox?
问题描述
有谁知道哪个属性设置了禁用控件的文本颜色?我必须在禁用的 TextBox
中显示一些文本,我想将其颜色设置为黑色.
Does anyone know which property sets the text color for disabled control?
I have to display some text in a disabled TextBox
and I want to set its color to black.
推荐答案
注意: 请参阅下面的 Cheetah 答案,因为它确定了使此解决方案起作用的先决条件.设置TextBox
的BackColor
.
NOTE: see Cheetah's answer below as it identifies a prerequisite to get this solution to work. Setting the BackColor
of the TextBox
.
我认为您真正想要做的是启用 TextBox
并将 ReadOnly
属性设置为 true
.
I think what you really want to do is enable the TextBox
and set the ReadOnly
property to true
.
在禁用的 TextBox
中更改文本颜色有点棘手.我认为您可能需要子类化并覆盖 OnPaint
事件.
It's a bit tricky to change the color of the text in a disabled TextBox
. I think you'd probably have to subclass and override the OnPaint
event.
ReadOnly
虽然应该给你与 !Enabled
相同的结果,并允许你保持对 TextBox
的颜色和格式的控制.我认为它仍然支持从 TextBox
选择和复制文本,这在禁用 TextBox
的情况下是不可能的.
ReadOnly
though should give you the same result as !Enabled
and allow you to maintain control of the color and formatting of the TextBox
. I think it will also still support selecting and copying text from the TextBox
which is not possible with a disabled TextBox
.
另一种简单的替代方法是使用 Label
而不是 TextBox
.
Another simple alternative is to use a Label
instead of a TextBox
.
这篇关于如何更改禁用的 TextBox 的字体颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!