111,126
社区成员
发帖
与我相关
我的任务
分享
遇到,一个问题了。
比如:
"当我用 select 的方法可以做到改部分 color 与font"
但是:
"我不想把当标的位置变了。"
因为:
"我是在线输入,要样它在线变色."
大家都用才vs 编辑器吧,我想让 richTextBox 同它一样。
实现在线变色。//我的是用正则来比较它。
"求救"啊。

string pattern = @"[\+\-\*\/={}]+";
bool ismatch = Regex.IsMatch(rtbSource.Text.Trim(), pattern);
if (ismatch)
{
int i = 0;
MatchCollection mc = Regex.Matches(rtbSource.Text.Trim(), pattern);
foreach (Match smc in mc)
{
rtbSource.Select(i, smc.Value.Length);
rtbSource.SelectionBackColor = Color.Blue;
rtbSource.SelectionFont = new Font(@"宋体", 12);
i = i + smc.Value.Length + 1;
}
}
string pattern = @"[\d]{3}[-\/][\d]{7}|[\d]{4}[-\/][\d]{6}|[\d]{11}|[(][\d]{3}[)][\d]{7}";
bool ismatch = Regex.IsMatch(richTextBox1.Text.Trim(), pattern);
if (ismatch)
{
int i = 0;
MatchCollection mc = Regex.Matches(richTextBox1.Text.Trim(), pattern);
foreach (Match smc in mc)
{
richTextBox1.Select(i, smc.Value.Length);
richTextBox1.SelectionBackColor = Color.Blue;
richTextBox1.SelectionFont = new Font(@"宋体", 20);
i = i + smc.Value.Length + 1;
}
}
string pattern = @"[\d]{3}[-\/][\d]{7}|[\d]{4}[-\/][\d]{6}|[\d]{11}|[(][\d]{3}[)][\d]{7}";
bool ismatch = Regex.IsMatch(richTextBox1.Text.Trim(), pattern);
if (ismatch)
{
int i = 0;
MatchCollection mc = Regex.Matches(richTextBox1.Text.Trim(), pattern);
foreach (Match smc in mc)
{
richTextBox1.Select(i, smc.Value.Length);
richTextBox1.SelectionBackColor = Color.Blue;
richTextBox1.SelectionFont = new Font(@"宋体", 10);
i = i + smc.Value.Length + 1;
// richTextBox1.SelectionStart = 0;
}
}
public class selectText
{
public int index;
public int length;
public selectText();
public selectText(int index,int length) {
this.index = index;
this.length = length;
}
}
List<selectText> 
string pattern = @"[\d]{3}[-\/][\d]{7}|[\d]{4}[-\/][\d]{6}|[\d]{11}|[(][\d]{3}[)][\d]{7}";
richTextBox1.SelectionBackColor
richTextBox1.SelectionFont
richTextBox1.SelectionStart