【问题标题】:Change a textbox colour when disabled C# [duplicate]禁用C#时更改文本框颜色[重复]
【发布时间】:2020-04-22 06:36:59
【问题描述】:

我会问和我看过的其他话题一样的问题。

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

【问题讨论】:

  • 如果你以前见过同样的问题,为什么还要再问呢?重复问题的答案是什么?

标签: c# textbox


【解决方案1】:

当一个文本框被禁用时,它会忽略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
}

【讨论】:

  • 我该怎么办?你能举个例子(代码)吗?
  • 我已经更新了我的答案...看看这是否对你有帮助!!! :)
  • @user2698690:- 这对你有用吗???
【解决方案2】:

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

【讨论】:

    猜你喜欢
    • 2016-11-20
    • 1970-01-01
    • 2013-02-19
    • 1970-01-01
    • 1970-01-01
    • 2013-02-15
    • 2010-12-29
    • 2023-04-01
    • 2011-12-25
    相关资源
    最近更新 更多