RichTextBox选择文本的分量
本文关键字:分量 文本 选择 RichTextBox | 更新日期: 2023-09-27 17:49:49
我有RichTextBox
。我如何选择/*
和*/
之间的文本并使该文本为绿色?
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;
});