English 中文(简体)
内容丰富的方框
原标题:simple text color in rich text box
  • 时间:2009-11-05 21:31:05
  •  标签:

我可以找到100万个例子,说明如何做reg事,以把 highlighting子放在一个丰富的文字箱上。 但是,我需要的是简单的方式,用大颜色来补充。

该守则将“世界之声”这一词语列入一个文本箱,而“世界之声”是红色的,世界是绿色的?

该法典的工作。

this.richTextBox1.SelectionColor = Color.Red
this.richTextBox1.text += "Test"
最佳回答

在你提出后选择案文,然后改写。

例如:

richTextBox1.Text += "Test"
richTextBox1.Select(richTextBox1.TextLength - 4, 4)
richTextBox1.SelectionColor = Color.Red
问题回答

该法典为RichTextBox增加了红色彩色的“Hello”和绿色的“World”文本。

RichTextBox1.SelectionColor = Color.Red
RichTextBox1.SelectedText = "Hello "
RichTextBox1.SelectionColor = Color.Green
RichTextBox1.SelectedText = "World"

Ive worked with it in VB6 and i think its the same: You must select the text and then apply

this.richTextBox1.SelectionColor = Color.Red

添加的案文总是出现在光彩中,你必须选择它,然后改变其肤色:

this.richTextBox1.text="Hello world!"
this.richTextBox1.selstart=0
this.richTextBox1.sellength=5
this.richTextBox1.SelectionColor = Color.Red

As i dont use vb.net, you must check the spelling but i think thats the key. The code i wrote is supposed to print "Hello" in red and "World!" in black.

引言

    RichTextBox2.SelectionLength = 0
    RichTextBox1.SelectionStart = 0
      We deselect everything first in case the user has something selected.
    RichTextBox1.SelectionColor = Color.Red
    RichTextBox1.SelectedText = "Hello "
    RichTextBox1.SelectionColor = Color.Green
    RichTextBox1.SelectedText = "World "

这将增加案文箱的开始。 我认为,你还可以使甄选标准=RichTextBox1。 案文将结束,而不是开始。

该法典没有工作:

this.richTextBox1.SelectionColor = Color.Red
this.richTextBox1.text += "Test"

将第二行改为:

this.richTextBox1.SelectionColor = Color.Red
this.richTextBox1.selectedtext = "Test"

引言

Sub colorWord(ByVal word As String, ByVal color As Color)   by im4dbr0
        For i As Integer = 0 To RichTextBox1.TextLength
            Try
                If RichTextBox1.Text.ElementAt(i).ToString = word.ElementAt(0).ToString Then
                    Dim found As Boolean = False
                    For j As Integer = 1 To word.Count - 1
                        If RichTextBox1.Text.ElementAt(i + j) = word.ElementAt(j) Then
                            found = True
                        Else
                            found = False
                            Exit For
                        End If
                    Next
                    If found = True Then
                        RichTextBox1.Select(i, word.Length)
                        RichTextBox1.SelectionColor = color
                    End If
                End If
            Catch ex As Exception
                Continue For
            End Try
        Next

多个词使用假

 Dim Words As New List(Of String)
        Words.Add("Its")
        Words.Add("That")
        Words.Add("Simple")
        For i As Integer = 0 To Words.Count - 1
            colorWord(Words.Item(i), Color.Red)
        Next




相关问题
热门标签