Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Rich Text Box Colors? [modified]

Rich Text Box Colors? [modified]

Scheduled Pinned Locked Moved Visual Basic
winformsgraphicsquestionannouncement
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    BadBoyTazz4Ever
    wrote on last edited by
    #1

    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, 2007

    I Live In My Own Little World! But It's Ok, They Know Me Here!

    M 1 Reply Last reply
    0
    • B BadBoyTazz4Ever

      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, 2007

      I Live In My Own Little World! But It's Ok, They Know Me Here!

      M Offline
      M Offline
      Martin Smith
      wrote on last edited by
      #2

      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

      B 1 Reply Last reply
      0
      • M Martin Smith

        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

        B Offline
        B Offline
        BadBoyTazz4Ever
        wrote on last edited by
        #3

        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!

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups