0

我要问和我见过的其他话题一样的问题。

当我使用 Textbox.Enable 或 Textbox.readOnly 时,文本框变为深色,如何更改此颜色以获得更好的颜色?(白色可能会更好)。

4

2 回答 2

1

当 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
}
于 2013-08-20T06:10:19.500 回答
0

通过自定义文本框覆盖 OnPaint 方法。
此外,您还可以看到:如何更改已禁用文本框的字体颜色?

于 2013-08-20T06:23:02.950 回答