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. C#
  4. rtb formatting problems

rtb formatting problems

Scheduled Pinned Locked Moved C#
jsontutorialquestionlounge
6 Posts 3 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.
  • S Offline
    S Offline
    SoftcodeSoftware
    wrote on last edited by
    #1

    I have been trying for a couple of days with no success at formatting some text in a rtb control. I will be entering something like this on each line: "username: the chat message" I want "username: " to be bold for example. All that ever happens is that EVERYTHING is turned bold, or only the first instance of "username: ", the rest ignored. Does anyone know what the best way to do this is? Cheers, Ben.

    I Y 2 Replies Last reply
    0
    • S SoftcodeSoftware

      I have been trying for a couple of days with no success at formatting some text in a rtb control. I will be entering something like this on each line: "username: the chat message" I want "username: " to be bold for example. All that ever happens is that EVERYTHING is turned bold, or only the first instance of "username: ", the rest ignored. Does anyone know what the best way to do this is? Cheers, Ben.

      I Offline
      I Offline
      Ingo
      wrote on last edited by
      #2

      Well you have to select "username:" There is a function Select(start, length) for the RichTextBox. In this case rtfbox.Select(0, 9); Then you can set the "SelectionFont": rtfbox.SelectionFont = new Font(rtfbox.Font, FontStyle.Bold); The username: should be bold. Regards, Ingo

      ------------------------------ PROST Roleplaying Game War doesn't determine who's right. War determines who's left.

      S 1 Reply Last reply
      0
      • S SoftcodeSoftware

        I have been trying for a couple of days with no success at formatting some text in a rtb control. I will be entering something like this on each line: "username: the chat message" I want "username: " to be bold for example. All that ever happens is that EVERYTHING is turned bold, or only the first instance of "username: ", the rest ignored. Does anyone know what the best way to do this is? Cheers, Ben.

        Y Offline
        Y Offline
        yueue
        wrote on last edited by
        #3

        good work

        1 Reply Last reply
        0
        • I Ingo

          Well you have to select "username:" There is a function Select(start, length) for the RichTextBox. In this case rtfbox.Select(0, 9); Then you can set the "SelectionFont": rtfbox.SelectionFont = new Font(rtfbox.Font, FontStyle.Bold); The username: should be bold. Regards, Ingo

          ------------------------------ PROST Roleplaying Game War doesn't determine who's right. War determines who's left.

          S Offline
          S Offline
          SoftcodeSoftware
          wrote on last edited by
          #4

          Thanks, but that still only does one instance of the term - I think it's finding the first instance and applying it to that over and over again - is there a way to find a string's position searching from the end instead of the beginning at all? -- modified at 6:24 Thursday 3rd August, 2006

          I 1 Reply Last reply
          0
          • S SoftcodeSoftware

            Thanks, but that still only does one instance of the term - I think it's finding the first instance and applying it to that over and over again - is there a way to find a string's position searching from the end instead of the beginning at all? -- modified at 6:24 Thursday 3rd August, 2006

            I Offline
            I Offline
            Ingo
            wrote on last edited by
            #5

            SoftcodeSoftware wrote:

            Thanks, but that still only does one instance of the term - I think it's finding the first instance and applying it to that over and over again - is there a way to find a string's position searching from the end instead of the beginning at all?

            You can search the position of a string: str.IndexOf("username:"); or str.LastIndexOf("username:"); So you can search every part of the string you want bold and then select it and set it bold like in the first answer I gave. example: string searchstr[] = new string[]; searchstr[0] = "username:"; for (int i = 0; i < searchstr.Length; i++) { rtfbox.Select(rtfbox.Text.IndexOf(searchstr[i]), searchstr[i].Length); ... } Regards, Ingo -- modified at 6:57 Thursday 3rd August, 2006

            ------------------------------ PROST Roleplaying Game War doesn't determine who's right. War determines who's left.

            S 1 Reply Last reply
            0
            • I Ingo

              SoftcodeSoftware wrote:

              Thanks, but that still only does one instance of the term - I think it's finding the first instance and applying it to that over and over again - is there a way to find a string's position searching from the end instead of the beginning at all?

              You can search the position of a string: str.IndexOf("username:"); or str.LastIndexOf("username:"); So you can search every part of the string you want bold and then select it and set it bold like in the first answer I gave. example: string searchstr[] = new string[]; searchstr[0] = "username:"; for (int i = 0; i < searchstr.Length; i++) { rtfbox.Select(rtfbox.Text.IndexOf(searchstr[i]), searchstr[i].Length); ... } Regards, Ingo -- modified at 6:57 Thursday 3rd August, 2006

              ------------------------------ PROST Roleplaying Game War doesn't determine who's right. War determines who's left.

              S Offline
              S Offline
              SoftcodeSoftware
              wrote on last edited by
              #6

              Excellent, thanks, Im all sorted now :)

              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