当禁用C#时更改文本框颜色[重复]

问题描述 投票:0回答:2

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

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

c# textbox
2个回答
1
投票

禁用TextBox时,它将忽略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
}

0
投票

通过自定义文本框覆盖OnPaint方法。另外,您可能会看到:How to change the font color of a disabled TextBox?

© www.soinside.com 2019 - 2024. All rights reserved.