2012-10-19 190 views
0

我有Rich文本框和它的命名textBox1豐富的文本框Color.Red不存在

當我試試這個:

    textBox1.AppendText(value); 
        textBox1.SelectionColor = Color.Red; 

Red有下劃線且出錯:

Error 2 'string' does not contain a definition for 'Red' and no extension method 'Red' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?) Form1.cs 73 57

+0

確保您使用的顏色對象正確的命名空間。 – Tariqulazam

+6

你的表單是否有名爲'Color'的字段或屬性?如果是這樣,您需要通過指定'System.Drawing.Color.Red'來消除歧義。 –

+0

@Michael Liu,發貼爲答案 – Andrew

回答

2

您的表格是否有名爲Color的字段或屬性,其類型爲string?如果是這樣,那麼Color.Red中的「顏色」是指該字段或屬性而不是System.Drawing.Color類型。

您可以通過指定System.Drawing命名空間歧義參考:

textBox1.SelectionColor = System.Drawing.Color.Red;