本文介绍了禁用 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# 时更改文本框颜色
发布评论