【发布时间】:2020-04-22 06:36:59
【问题描述】:
我会问和我看过的其他话题一样的问题。
当我使用 Textbox.Enable 或 Textbox.readOnly 时,文本框会变成深色,如何更改此颜色以获得更好的颜色? (白色可能更好)。
【问题讨论】:
-
如果你以前见过同样的问题,为什么还要再问呢?重复问题的答案是什么?
我会问和我看过的其他话题一样的问题。
当我使用 Textbox.Enable 或 Textbox.readOnly 时,文本框会变成深色,如何更改此颜色以获得更好的颜色? (白色可能更好)。
【问题讨论】:
当一个文本框被禁用时,它会忽略ForeColor。您可以通过实现自定义绘画来覆盖它。
来自Thread:-
您可以像这样覆盖 OnPaint 事件:-
protected override void OnPaint(PaintEventArgs e)
{
SolidBrush drawBrush = new SolidBrush(ForeColor);
// Draw string to screen.
e.Graphics.DrawString(Text, Font, drawBrush, 0f,0f);
}
set the ControlStyles to "UserPaint"
public MyTextBox()//constructor
{
// This call is required by the Windows.Forms Form Designer.
this.SetStyle(ControlStyles.UserPaint,true);
InitializeComponent();
// TODO: Add any initialization after the InitForm call
}
【讨论】:
通过自定义文本框覆盖 OnPaint 方法。
另外,你可以看到这个:How to change the font color of a disabled TextBox?
【讨论】: