Change a textbox colour when disabled C# [duplicate]

早过忘川 提交于 2019-12-13 04:31:31

问题


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

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).


回答1:


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

From the source Thread:-

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
}



回答2:


Override OnPaint method by costomising the textbox.
Also see this : How to change the font color of a disabled TextBox?



来源:https://stackoverflow.com/questions/18328024/change-a-textbox-colour-when-disabled-c-sharp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!