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. RichTextBox

RichTextBox

Scheduled Pinned Locked Moved C#
tutorialquestion
2 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.
  • M Offline
    M Offline
    mihksoft
    wrote on last edited by
    #1

    Hy I have a RichTextBox and I typing words separated with SPACE. I want to set different color for each word typed. Can anybody tell me how can I do that or give me an short example. Thanks

    W 1 Reply Last reply
    0
    • M mihksoft

      Hy I have a RichTextBox and I typing words separated with SPACE. I want to set different color for each word typed. Can anybody tell me how can I do that or give me an short example. Thanks

      W Offline
      W Offline
      wienzzz
      wrote on last edited by
      #2

      Hai mihk, I'm working on similar application also. In my opinion, you can do that on 2 ways. 1. scan through the first char loop until end, when you find "SPACE" / "32" in ASCII, you just put a little code of RTF Formatting. well, let's just say like this. StringResult = ""; //this is the header for RTF-format StringResult = {\rtf\ansi {\colortbl; \red0\green0\blue255;\red255\green0\blue0;}; //2 color, Blue and Red bool toggle = false; for(int i=0; i < YourString.GetLength(0); i++) { if(toggle) { StringResult = StringResult + @"\cf1"; } else StringResult = StringResult + @"\cf2"; StringResult = StringResult + YourString[i]; if(YourString[i] == (char)32) { //toggle the boolean if(toggle) toggle = false; else toggle = true; } } you may search more about RTF formatting on microsoft web site. 2. you can just use the method RTB.Selection to change the font, forecolor, backcolor, etc. find more info about this on MSDN help. CMIIW

      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