禁用 C# 时更改文本框颜色

编程入门 行业动态 更新时间:2024-10-24 13:18:26
本文介绍了禁用 C# 时更改文本框颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我要问同样的问题,就像我看到的其他话题一样.

i am going to ask the same thing like other topic which I have seen.

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

When i use the Textbox.Enable or Textbox.readOnly, the textbox gets a dark colour, how can i change this colour for a better colour? (white could be better).

推荐答案

禁用 TextBox 时,它会忽略 ForeColor.您可以通过实现自定义绘画来覆盖它.

When a TextBox is disabled, it ignores the ForeColor. You can override this by implementing your custom painting.

来自线程:-

您可以像这样覆盖 OnPaint 事件:-

You can override the OnPaint event like something like this:-

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 }

更多推荐

禁用 C# 时更改文本框颜色

本文发布于:2023-06-09 04:11:41,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/594976.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文本框   颜色

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!