2

我有RichTextBox。如何在和之间选择文本/*并使*/该文本变为绿色?

4

1 回答 1

2
string text = "abc /*defg*/ hij /*klm*/ xyz";
richTextBox1.Text = text;

Regex.Matches(text, @"\/\*(.*?)\*\/",RegexOptions.Singleline).Cast<Match>()
        .ToList()
        .ForEach(m =>
        {
            richTextBox1.Select(m.Index, m.Value.Length);
            richTextBox1.SelectionColor = Color.Blue;
            //or 
            //richTextBox1.Select(m.Groups[1].Index, m.Groups[1].Value.Length);
            //richTextBox1.SelectionColor = Color.Blue;
        });
于 2012-12-29T21:47:45.033 回答