在 winform 上突出显示字符串之间的差异
Highlight differences between strings on winform
我希望有人能帮我解决这个问题,希望这个问题不会太含糊。
我正在尝试确定一种方法来突出显示 winform 中两个文本字符串之间的差异。
我在数据网格的一列中有原始字符串,在第二列中有要比较的字符串。我想要突出显示比较字符串在数据网格视图本身中的不同之处。
示例:
Thanks for the hep
Thanks for the help!!
其中 l
和两个 !
将被突出显示
我尝试了以下方法(向 Bouam 大声疾呼,寻求他的帮助 Previous Post):
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;
}
}
}
但这只会突出显示哪些行不同,而不是在字符级别。我对这一切都不熟悉,所以这是一项疯狂的尝试吗?
任何人都可以帮助或指出有用的资源吗?
您可以在 RichTextBox
的基础上创建一个新的 DatGridViewColumn
,然后使用您的新富文本列,以突出富文本中的差异。
这可能对您有帮助:
这是基于此的输出:
您可以应用您需要的算法来比较字符串与列的差异,并使用此 DataGridViewRichTextBoxColumn
突出显示差异。
要了解有关创建自定义 datagridview 列类型的更多信息,您可以查看 Build a Custom NumericUpDown Cell and Column for the DataGridView Control。
我希望有人能帮我解决这个问题,希望这个问题不会太含糊。
我正在尝试确定一种方法来突出显示 winform 中两个文本字符串之间的差异。
我在数据网格的一列中有原始字符串,在第二列中有要比较的字符串。我想要突出显示比较字符串在数据网格视图本身中的不同之处。
示例:
Thanks for the hep
Thanks for the help!!
其中 l
和两个 !
将被突出显示
我尝试了以下方法(向 Bouam 大声疾呼,寻求他的帮助 Previous Post):
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;
}
}
}
但这只会突出显示哪些行不同,而不是在字符级别。我对这一切都不熟悉,所以这是一项疯狂的尝试吗?
任何人都可以帮助或指出有用的资源吗?
您可以在 RichTextBox
的基础上创建一个新的 DatGridViewColumn
,然后使用您的新富文本列,以突出富文本中的差异。
这可能对您有帮助:
这是基于此的输出:
您可以应用您需要的算法来比较字符串与列的差异,并使用此 DataGridViewRichTextBoxColumn
突出显示差异。
要了解有关创建自定义 datagridview 列类型的更多信息,您可以查看 Build a Custom NumericUpDown Cell and Column for the DataGridView Control。