简体   繁体   English

在 winform 上突出显示字符串之间的差异

[英]Highlight differences between strings on winform

I am hoping somebody can help me out here and that this questions won't be too vague.我希望有人能在这里帮助我,并且这个问题不会太模糊。

I am trying to determine a way that I can highlight the differences between two text strings within a winform.我正在尝试确定一种可以突出显示 winform 中两个文本字符串之间差异的方法。

I have the original string in one column of a data grid and the string to compare to in a second column.我在数据网格的一列中有原始字符串,在第二列中有要比较的字符串。 What I would like is to highlight where the comparison string is different within the data grid view itself.我想突出显示数据网格视图本身中比较字符串的不同之处。

Example:例子:

Thanks for the hep

Thanks for the help!!

where the l , and two !哪里的l和两个! would be highlighted将被突出显示

I have tried the following (Shout out to Bouam for his help in this Previous Post ):我尝试了以下方法(在上一篇文章中向 Bouam 寻求帮助):

for (int i = 0; i < TextProcessingResults.RowCount; i++)
{
    if (TextProcessingResults.Rows[i].Cells[1].Value != null)
    {
        if ((string)TextProcessingResults.Rows[i].Cells[1].Value != (string)TextProcessingResults.Rows[i].Cells[2].Value)
        {
            TextProcessingResults.Rows[i].DefaultCellStyle.ForeColor = Color.Red;
        }
    }
}

But this only highlights which rows are different not at the character level.但这只会突出显示哪些行在字符级别不同。 I'm new to all of this, so is this a crazy endeavor to undertake?我对这一切都不熟悉,所以这是一个疯狂的尝试吗?

Could anybody help or point me towards a resource that would be useful?有人可以帮助或指出我有用的资源吗?

You can create a new DatGridViewColumn based on RichTextBox and then use your new rich text column, to highlight differences in rich text.您可以基于RichTextBox创建一个新的DatGridViewColumn ,然后使用新的富文本列来突出显示富文本中的差异。

This may help you:这可能会帮助您:

And here is an ouptput based on this:这是基于此的输出:

在此处输入图片说明

You can apply the algorithm you need to compare strings for differences to columns and using this DataGridViewRichTextBoxColumn highlight the differences.您可以应用需要比较字符串与列的差异的算法,并使用此DataGridViewRichTextBoxColumn突出显示差异。

To learn more about creating custom datagridview column types you can take a look atBuild a Custom NumericUpDown Cell and Column for the DataGridView Control .要了解有关创建自定义 datagridview 列类型的更多信息,您可以查看为 DataGridView 控件构建自定义 NumericUpDown 单元格和列

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM