M
mpdillon56
Guest
I am adding characters to a RichTextBox one character at a time and setting the format of that character after it is added. The following code is a distillation of the actual code but reliably repeats the problem I am having.
The code should place a Blue "S", a Red "S" and a Green "S" in to the RichTextBox when i = 3.
When the code is executed it returns a Blue "S", Blue "S" and a Green "S".
While that is odd to me and unexpected, where it happens in the code is even stranger. By stepping through the code, prematurely going to the End Sub and then displaying the form, I was able to determine that when i = 3 and the line "Me.RichTextBox1.Text = Me.RichTextBox1.Text & "S" is exceuted, the color of the first two "S" are changed from Blue and Red to all BLUE.
I do not understand. Could someone please offer a way to add characters to a RichtextBox and set the formatting of those characters?
This example is just color. I the real project I am setting Size, Color, Bold and Italics. I do not know if the solution to this color problem will affect the other formatting information.
thanks,
pat
Dim L As Integer = 0
Dim i As Integer = 1
Me.RichTextBox1.Text = ""
For i = 1 To 3
L = Me.RichTextBox1.Text.Length
Me.RichTextBox1.Text = Me.RichTextBox1.Text & "S"
Me.RichTextBox1.Select(L, 1)
'
'Color
Select Case i
Case 1
Me.RichTextBox1.SelectionColor = Color.Blue
Case 2
Me.RichTextBox1.SelectionColor = Color.Red
Case 3
Me.RichTextBox1.SelectionColor = Color.Green
Case 4
Me.RichTextBox1.SelectionColor = Color.Black
Case Else
Me.RichTextBox1.SelectionColor = Color.Black
End Select
Next i
Continue reading...
The code should place a Blue "S", a Red "S" and a Green "S" in to the RichTextBox when i = 3.
When the code is executed it returns a Blue "S", Blue "S" and a Green "S".
While that is odd to me and unexpected, where it happens in the code is even stranger. By stepping through the code, prematurely going to the End Sub and then displaying the form, I was able to determine that when i = 3 and the line "Me.RichTextBox1.Text = Me.RichTextBox1.Text & "S" is exceuted, the color of the first two "S" are changed from Blue and Red to all BLUE.
I do not understand. Could someone please offer a way to add characters to a RichtextBox and set the formatting of those characters?
This example is just color. I the real project I am setting Size, Color, Bold and Italics. I do not know if the solution to this color problem will affect the other formatting information.
thanks,
pat
Dim L As Integer = 0
Dim i As Integer = 1
Me.RichTextBox1.Text = ""
For i = 1 To 3
L = Me.RichTextBox1.Text.Length
Me.RichTextBox1.Text = Me.RichTextBox1.Text & "S"
Me.RichTextBox1.Select(L, 1)
'
'Color
Select Case i
Case 1
Me.RichTextBox1.SelectionColor = Color.Blue
Case 2
Me.RichTextBox1.SelectionColor = Color.Red
Case 3
Me.RichTextBox1.SelectionColor = Color.Green
Case 4
Me.RichTextBox1.SelectionColor = Color.Black
Case Else
Me.RichTextBox1.SelectionColor = Color.Black
End Select
Next i
Continue reading...