با تشكر از اساتيد من يك كدي زدم فايلش هم گذاشتم نظرتون چيه؟؟اگر مي شد اخرين پرانتز كه تغيير مي كنه فقط رنگي ميشد بهتر بود ایا میشه وسط متن هم اگر پرانتز باز پاک بشه فقط اون رنگی بشه؟!!!
private void CheckKeyword(string word, Color color, int startIndex) {
if (this.richTextBox1.Text.Contains(word))
{
int index = -1;
int selectStart = this.richTextBox1.SelectionStart;
while ((index = this.richTextBox1.Text.IndexOf(word, (index + 1))) != -1)
{
this.richTextBox1.Select((index + startIndex), word.Length);
this.richTextBox1.SelectionColor = color;
this.richTextBox1.Select(selectStart, 0);
this.richTextBox1.SelectionColor = Color.Black;
}
}
}
public static int CountStringOccurrences(string text, string pattern) //??? ????? ???? ???
{
int count = 0;
int i = 0;
while ((i = text.IndexOf(pattern, i)) != -1)
{
i += pattern.Length;
count++;
}
{
return count;
}
}
private void richTextBox1_TextChanged(object sender, EventArgs e)
{
string rich1 = richTextBox1.Text;
int shomare1 = CountStringOccurrences(rich1, "("); // // 1????? ??????
int shomare2 = CountStringOccurrences(rich1, ")");// // ????? ??????2
if (shomare1 - shomare2 == 0)
{
this.CheckKeyword(")", Color.Black, 0);
this.CheckKeyword("(", Color.Black, 0);
return;
}
if (shomare1 - shomare2 > 0)
{
this.CheckKeyword("(", Color.Gray, 0);// // ???? ????
}
if (shomare1 - shomare2 < 0)
{
this.CheckKeyword(")", Color.Red, 0);// // ???? ????
}
}