2
我有一個我使用的richTextBox,因此用戶可以看到他們擁有的XML文件並讓它們編輯它。我有一些代碼將關鍵字顏色更改爲我指定的顏色。這是我使用的方法:當點擊一個彩色字符串旁邊時,richtextbox讓我使用該顏色而不是黑色
private void CheckKeyword(string word, Color color, int startIndex)
{
if (this.richTextBox.Text.Contains(word))
{
int index = -1;
int selectStart = this.richTextBox.SelectionStart;
while ((index = this.richTextBox.Text.IndexOf(word, (index + 1))) != -1)
{
this.richTextBox.Select((index + startIndex), word.Length);
this.richTextBox.SelectionColor = color;
this.richTextBox.Select(selectStart, 0);
this.richTextBox.SelectionColor = Color.Black;
}
}
}
的問題是,當我點擊 near a coloured string,我開始輸入in that specific colour.
我知道爲什麼它的發生,但不知道如何解決它。
謝謝!!!!這工作完美! – MosesTheHoly