更改特定单词的选择颜色 [英] Changing selection color of a specific word

查看:108
本文介绍了更改特定单词的选择颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我今天心情很好:)



我的项目获取ID时,会在富文本框中将RFID标签ID显示为字符串。



修改后代码如下:



识别号码:66006C43C78E

授权ID:☑正确☑[Rixterz]

授权访问



这是我的代码到目前为止:



Hello everyone, I'm in a good mood today :)

My project displays the RFID tag ID as a string in a richtextbox when it gets the ID.

The code comes out like this after modification:

Identification Number: 66006C43C78E
Authorised ID: ☑ TRUE ☑ [Rixterz]
Access Granted

This is my code so far:

Dim RedWords() As String = {"☒ FALSE ☒", "Access Denied"}
    Dim GreenWords() As String = {"☑ TRUE ☑", "Access Granted"}
    Dim NormalYellowWords() As String = {"Identification Number:", "Authorised ID:"}

Dim index As Integer
        Dim Position As Integer
        Position = RichTextBox1.SelectionStart
        RichTextBox1.Select(index, RichTextBox1.Text.Length)
        RichTextBox1.SelectionColor = Color.Blue
        RichTextBox1.DeselectAll()

        For Word As Integer = 0 To NormalYellowWords.Count - 1 Step 1
            index = RichTextBox1.Text.IndexOf(NormalYellowWords(Word))
            If index <> -1 Then
                RichTextBox1.Select(index, NormalYellowWords(Word).Length)
                RichTextBox1.SelectionColor = Color.Yellow
                RichTextBox1.DeselectAll()
                RichTextBox1.SelectionStart = Position
            End If
            RichTextBox1.SelectionColor = Color.Yellow
        Next

        For Word As Integer = 0 To RedWords.Count - 1 Step 1
            index = RichTextBox1.Text.IndexOf(RedWords(Word))
            If index <> -1 Then
                RichTextBox1.Select(index, RedWords(Word).Length)
                RichTextBox1.SelectionColor = Color.Red
                RichTextBox1.DeselectAll()
                RichTextBox1.SelectionStart = Position
            End If
            RichTextBox1.SelectionColor = Color.Yellow
            index = RichTextBox1.Text.IndexOf(RedWords(Word)) + RedWords(Word).Length
        Next

        For Word As Integer = 0 To GreenWords.Count - 1 Step 1
            index = RichTextBox1.Text.IndexOf(GreenWords(Word))
            If index <> -1 Then
                RichTextBox1.Select(index, GreenWords(Word).Length)
                RichTextBox1.SelectionColor = Color.Lime
                RichTextBox1.DeselectAll()
                RichTextBox1.SelectionStart = Position
            End If
            RichTextBox1.SelectionColor = Color.Yellow
        Next





为了使输出更容易阅读,我希望NormalYellowWords是一个基本的黄色,红色字是红色,绿色字是石灰。这留下了标签ID,它应该是蓝色的。



这对标签的第二次扫描不起作用,那么如何更改多次出现的颜色在richtextbox1.text中的单词?



-Ricky



To make the output easier to read, I would like the NormalYellowWords to be a basic yellow, the redwords to be red and the greenwords to be lime. That leaves the tag ID, which should be blue.

This doesn't work for a second scan of the tag so how do I change colours of multiple occurences of a word in richtextbox1.text?

-Ricky

推荐答案

检查这些我的帮助你:

查找并着色所有RichTextBox中出现的字符串 [ ^ ]

[ ^ ]

在RichTextBox中搜索并突出显示文本 [ ^ ]
Check these which my help you:
Find and color all occurences of a String in a RichTextBox[^]
Change color of all instances of a Word(s) in RichTextBox[^]
Search and Highlight Text in a RichTextBox[^]


这篇关于更改特定单词的选择颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆