2009-05-26 85 views
3

我想選擇一個特定的文本行,並用藍色突出顯示它,並且我希望該文本的前景色爲白色。 我試過richtextbox選擇顏色和選擇backcolor屬性

this.Select(start, length); 
this.SelectionBackColor = Color.Blue; 
this.SelectionColor = Color.White; 

但它不起作用。 有什麼不對? 我想模擬當我們通過鼠標選擇某些文本時獲得的效果,其中背景顏色變爲淺藍色,文本變爲白色。我能夠儘快獲得通過只是在做

this.Select(start, length); 

但隨後因爲它失去焦點,選擇消失,我想它是永久性的。

+0

我只是嘗試,它的工作原理對於我來說足夠了... – 2009-05-26 19:32:51

回答

2

試着做這樣的事情:

 this.richTextBox1.SelectionStart = start; 
     this.richTextBox1.SelectionLength = length; 
     this.richTextBox1.SelectionColor = Color.White; 
     this.richTextBox1.SelectionBackColor = Color.Blue; 
3

有一個在RichTextBox中以彩色文本更簡單的方法:

richtTextBox.SelectionColor = Color.Red; 
richTextBox.SelectedText = "Red text"; 
richtTextBox.SelectionColor = Color.Green; 
richTextBox.SelectedText = "Green text"; 

,你會得到: enter image description here