我希望能够在RichTextbox中突出显示(选择(文本,而不会影响当前的.selectionbackColor或.selectionColor
我有一个包含大量文本的RichTextbox。
我有一个listView,包含一个字符串/单词列表,这些字符串/单词在listView中具有不同的.backColor和.foreColor。
i通过.selectionBackColor和.selectionColor在RichTextbox中循环循环,并突出显示对应的文本。
For Each verItem As ListViewItem In lvVer.Items
startindex = 0
While startindex < rtbMain.TextLength
Dim wordStartIndex As Integer = rtbMain.Find(verItem.Text, startindex, RichTextBoxFinds.None)
If wordStartIndex <> -1 Then
rtbMain.SelectionStart = wordStartIndex
rtbMain.SelectionLength = verItem.Text.Length
rtbMain.SelectionBackColor = verItem.BackColor
rtbMain.SelectionColor = verItem.ForeColor
Else
Exit While
End If
startindex += wordStartIndex + verItem.Text.Length
End While
Next
这一切都很好,但是我希望能够在listView中选择一个项目,然后在带有标准亮点(蓝色背景,白色文本(颜色的RichTextbox中突出显示匹配的文本对象,而仍然保留下面的我的原始颜色。
如果我使用鼠标在RichTextbox中突出显示文本,它将在通常的Windows时尚(蓝色背景,白色文本(中暂时突出显示。如果我在RichTextbox中的其他地方单击鼠标,则我在字符串上设置的原始颜色仍然存在。我想在代码中复制此行为。
如果通过代码rtbMain.Select(wordStartIndex, verItem.Text.Length)
选择"选择"文本,则不会突出显示。它甚至似乎也没有视觉选择。显然,我可以设置一个新的.selectionbackcolor和.selectionColor,但后来我会失去原始颜色。
有没有办法通过编程来滚动鼠标在RichTextbox文本上滚动,并且在不影响基础原始颜色的情况下选择和突出显示文本?
我找到了答案,尽管很简单,但并不明显。
我必须将RichTextbox HiDelection属性设置为False。我知道,当您知道属性存在时,这很明显,但是,即使将其设置为false,当我双击一个单词或滚动鼠标上方时,选择可见?!?当我在代码中进行时,它只是不可见。