【发布时间】:2013-11-26 10:26:26
【问题描述】:
我正在尝试使用Regex 突出显示我的RichTextBox RTB 中的数字,它工作正常,除了当我按下将插入符号位置移动到我所在的位置上方时,它会选择下面的内容,当我输入,它消失了,除非我一直按左键,这真的很麻烦。
代码:
MyRegex.cs
namespace REGEX_MY
{
public class REGEX_CLASS
{
public static RichTextBox HIGHLIGHT(RichTextBox RTB, int StartPos)
{
Regex Red = new Regex("1|2|3|4|5|6|7|8|9|0");
RTB.SelectAll();
RTB.SelectionColor = Color.White;
RTB.Select(RTB.Text.Length, 1);
foreach (Match Match in Red.Matches(RTB.Text))
{
RTB.Select(Match.Index, Match.Length);
RTB.SelectionColor = Color.Blue;
RTB.SelectionStart = StartPos;
RTB.SelectionColor = Color.White;
}
return RTB;
}
}
}
MyForm.cs
public void DoIt()
{
RTB = REGEX_MY.REGEX_CLASS.HIGHLIGHT(RTB, RTB.SelectionStart);
}
谢谢:)
【问题讨论】:
标签: c# regex richtextbox