我會問像我看到的其他主題一樣的東西。禁用時更改文本框的顏色C#
當我使用Textbox.Enable或Textbox.readOnly時,文本框變暗,我如何更改顏色以獲得更好的顏色? (白色可能會更好)。
我會問像我看到的其他主題一樣的東西。禁用時更改文本框的顏色C#
當我使用Textbox.Enable或Textbox.readOnly時,文本框變暗,我如何更改顏色以獲得更好的顏色? (白色可能會更好)。
當文本框被禁用時,它會忽略ForeColor
。您可以通過實施自定義繪畫來覆蓋此內容。
從源頭Thread: -
您可以覆蓋OnPaint事件像這樣的事情: - 由costomising文本框中
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
}
覆蓋OnPaint方法。
也看到這個:How to change the font color of a disabled TextBox?
如果你以前見過同樣的問題,爲什麼再問一次?重複問題的答案是什麼? –