我在VB.NET 2010上进行了实验,并试图更改特定文本的颜色。更改标题的颜色RichTextBox VB.NET
我创建了拍摄的当前窗口标题,并在RichTextBox中实现了它的定时器:
Private Sub Timer3_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles activetitle.Tick
If strin <> GetActiveWindowTitle() Then
RichTextBox1.Text = RichTextBox1.Text & vbNewLine & vbNewLine & "[---" & GetActiveWindowTitle() & "---]") & vbNewLine & vbNewLine
strin = GetActiveWindowTitle()
End If
End Sub
不过,我试图改变代码,以便在当前的活动标题保存在RichTextBox的,它会出现在不同的颜色:
Private Sub Timer3_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles activetitle.Tick
If strin <> GetActiveWindowTitle() Then
RichTextBox1.Text = RichTextBox1.Text & vbNewLine & vbNewLine & "[---" & GetActiveWindowTitle() & "---]" & vbNewLine & vbNewLine
strin = GetActiveWindowTitle()
End If
If RichTextBox1.Text.Contains("[---" & "---]") Then
RichTextBox1.SelectionColor = Color.Red
End If
End Sub
我尝试许多不同的变化,并期待所有在互联网上为这个但没有成功:(
有谁知道我可以如何改变实现到RichTextBox中的当前活动窗口标题的颜色?
我想提醒你,我不希望在RichTextBox的颜色全变,但只有当前活动窗口标题:)
感谢的颜色提前所有评论!
你设置'SelectionColor'财产,但计时器逻辑似乎被忘记在更改颜色之前设置“SelectionStart”和“SelectionLength”。 – Icepickle
那么我应该如何改变这个代码呢? –
找到想要着色的文本位于文本框内,并将该位置设置为SelectionStart,然后将SelectionLength属性的长度设置为想要着色的文本的长度,然后应用SelectionColor – Icepickle