Rich Text Box Colors? [modified]
-
Hey Everybody! Well i need to display something like this on form: 15 + 10 = 10 + 5 + 10 now i tried gdi+ but i can't find a way to find out where like the 15 ended to start the + in another color so i thought the rich texy box would be easy'er but it seems it's been to long since i used it as well: the code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim varStart As Integer = 0 rtBox.Text = "Hallo" rtBox.Select(varStart, Len(rtBox.Text)) rtBox.SelectionColor = Color.Red rtBox.Refresh() MsgBox("Check 1") varStart = Len(rtBox.Text) rtBox.Text = rtBox.Text & " My Name Is " rtBox.Select(varStart, Len(rtBox.Text) - 1) rtBox.SelectionColor = Color.Black rtBox.Refresh() MsgBox("Check 2") varStart = Len(rtBox.Text) rtBox.Text = rtBox.Text & "BadBoyTazz" rtBox.Select(varStart, Len(rtBox.Text)) rtBox.SelectionColor = Color.Red rtBox.Refresh() End Sub
now the reason for the msgbox is just to force the pause of the code so that i can see how the rich text box refreshes! It does the same with or with out it! What happens here is it writes the "Hallo" in red, then the " My Name " in Black & then it writes everything in RED after i add "BadBoyTazz"! What am i missing to get it to look like this: Hallo My Name Is BadBoyTazz I can't see what the difference is between the first 2 words & when i add the "BadBoyTazz" Thanx... PS: If anybody can point me to a place where i can find the selution to the rich text box or gdi "version" please -- modified at 6:52 Monday 29th January, 2007I Live In My Own Little World! But It's Ok, They Know Me Here!
-
Hey Everybody! Well i need to display something like this on form: 15 + 10 = 10 + 5 + 10 now i tried gdi+ but i can't find a way to find out where like the 15 ended to start the + in another color so i thought the rich texy box would be easy'er but it seems it's been to long since i used it as well: the code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim varStart As Integer = 0 rtBox.Text = "Hallo" rtBox.Select(varStart, Len(rtBox.Text)) rtBox.SelectionColor = Color.Red rtBox.Refresh() MsgBox("Check 1") varStart = Len(rtBox.Text) rtBox.Text = rtBox.Text & " My Name Is " rtBox.Select(varStart, Len(rtBox.Text) - 1) rtBox.SelectionColor = Color.Black rtBox.Refresh() MsgBox("Check 2") varStart = Len(rtBox.Text) rtBox.Text = rtBox.Text & "BadBoyTazz" rtBox.Select(varStart, Len(rtBox.Text)) rtBox.SelectionColor = Color.Red rtBox.Refresh() End Sub
now the reason for the msgbox is just to force the pause of the code so that i can see how the rich text box refreshes! It does the same with or with out it! What happens here is it writes the "Hallo" in red, then the " My Name " in Black & then it writes everything in RED after i add "BadBoyTazz"! What am i missing to get it to look like this: Hallo My Name Is BadBoyTazz I can't see what the difference is between the first 2 words & when i add the "BadBoyTazz" Thanx... PS: If anybody can point me to a place where i can find the selution to the rich text box or gdi "version" please -- modified at 6:52 Monday 29th January, 2007I Live In My Own Little World! But It's Ok, They Know Me Here!
A while back I wrote some software to colour code a report that was displayed in an RTF box. Perhaps it will be of some use to you:
Private Sub Add_text_to_report(ByVal The_text As String, ByVal Style As System.Drawing.FontStyle, ByVal Colour As System.Drawing.Color)
Dim Font As New Font(rtBox.Font.FontFamily, rtBox.Font.Size, Style)
Dim Len As Integer = rtBox.Text.Length()' Add the text rtBox.AppendText(The\_text) ' Now format it as specified rtBox.SelectionStart = Len rtBox.SelectionLength = The\_text.Length rtBox.SelectionFont = Font rtBox.SelectionColor = Colour ' Clear the selection rtBox.SelectionStart = 0 End Sub
Simply add this sub-routine into your form and whenever you want to add text to the RTF Box just call the routine, specifying the string to add, its format (i.e. bold, underline etc, and its colour) Hope this helps, Regards
Martin
-
A while back I wrote some software to colour code a report that was displayed in an RTF box. Perhaps it will be of some use to you:
Private Sub Add_text_to_report(ByVal The_text As String, ByVal Style As System.Drawing.FontStyle, ByVal Colour As System.Drawing.Color)
Dim Font As New Font(rtBox.Font.FontFamily, rtBox.Font.Size, Style)
Dim Len As Integer = rtBox.Text.Length()' Add the text rtBox.AppendText(The\_text) ' Now format it as specified rtBox.SelectionStart = Len rtBox.SelectionLength = The\_text.Length rtBox.SelectionFont = Font rtBox.SelectionColor = Colour ' Clear the selection rtBox.SelectionStart = 0 End Sub
Simply add this sub-routine into your form and whenever you want to add text to the RTF Box just call the routine, specifying the string to add, its format (i.e. bold, underline etc, and its colour) Hope this helps, Regards
Martin
Thanx will give it a try! I see now what i missed "AppendText" just can't figure out why the example i've got works with out append but myne doesn't! Thanx again!
I Live In My Own Little World! But It's Ok, They Know Me Here!