我用来读取2个richtextbox内容的代码如下:
richTextBox1.Text = File.ReadAllText(tfsVersionFilePath);
richTextBox2.Text = File.ReadAllText(dbVersionFilePath);
Run Code Online (Sandbox Code Playgroud)
现在,我需要比较两个富文本框内容,并突出显示两个richtextbox中更改的字符.目的是as in TFS通过c#应用程序获得差异并突出显示字符(比较文件).谢谢.
编辑:
int length = (richTextBox1.Text.Length > richTextBox2.Text.Length) ? richTextBox1.Text.Length : richTextBox2.Text.Length;
for (int i = 0; i < length; i++)
{
if (richTextBox1.Text[i] != richTextBox2.Text[i])
{
/* and then start your highlight selection here,
this is where some difference between the two rich
text boxes begins */
richTextBox1.Select(i, 1);
richTextBox1.SelectionColor = System.Drawing.Color.Yellow;
richTextBox1.SelectionBackColor = System.Drawing.Color.Red;
}
}
Run Code Online (Sandbox Code Playgroud)
我从调试中理解的是,在执行特定行之后,指向文本光标的richTextBox1 Select或SelectionColor或SelectionBackColor方法增加到7个位置.如何保持 richTextBox1 …