2013-08-20 42 views
0

我會問像我看到的其他主題一樣的東西。禁用時更改文本框的顏色C#

當我使用Textbox.Enable或Textbox.readOnly時,文本框變暗,我如何更改顏色以獲得更好的顏色? (白色可能會更好)。

+8

如果你以前見過同樣的問題,爲什麼再問一次?重複問題的答案是什麼? –

回答

1

當文本框被禁用時,它會忽略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 
} 
+0

我該怎麼辦?你能舉一個例子(代碼)嗎? – user2698690

+0

我已經更新了我的答案......檢查是否可以幫助你! :) –

+1

@ user2698690: - 這有效嗎? –

相關問題