我要问和我见过的其他话题一样的问题。
当我使用 Textbox.Enable 或 Textbox.readOnly 时,文本框变为深色,如何更改此颜色以获得更好的颜色?(白色可能会更好)。
当 TextBox 被禁用时,它会忽略ForeColor
. 您可以通过实现自定义绘画来覆盖它。
从源线程: -
您可以像这样覆盖 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 方法。
此外,您还可以看到:如何更改已禁用文本框的字体颜色?