من با اين كد مي خواهم علامت}{ را رنگي كنم ولي وقتي رنگي ميشه ادامه كلمات هم رنگي ميشه در صورتي كه فقط مي خواهم اين علامتها رنگي بشه چه تغييري بدم. مرسي از توجه شما
private void richTextBoxCod_TextChanged(object sender, EventArgs e)
{
int shomare3 = CountStringOccurrences(rich1, "{"); // // 1شمردن پرانتز
int shomare4 = CountStringOccurrences(rich1, "}");// // شمردن پرانتز2
///.///......
if (shomare3 - shomare4 > 0)
{
this.ColorParantz("{", Color.Orange, 0);
}
else if (shomare3 - shomare4 < 0)
{
this.ColorParantz("}", Color.Red, 0);// // رنگي كردن
}
else
{
this.ColorParantz("}", Color.Black, 0);
this.ColorParantz("{", Color.Black, 0);
}
}
private void ColorParantz(string word, Color color, int startIndex)///متد {
if (this.richTextBoxCod.Text.Contains(word))
{
int index = -1;
int selectStart = this.richTextBoxCod.SelectionStart;
while ((index = this.richTextBoxCod.Text.IndexOf(word, (index + 1))) != -1)
{
// this.richTextBoxCod.Select(0,1);
this.richTextBoxCod.Select((index + startIndex), word.Length);
this.richTextBoxCod.SelectionColor = color;
this.richTextBoxCod.Select(selectStart, 0);
this.richTextBoxCod.SelectionColor = Color.Black;
}
}
}