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 / C++ / MFC
  4. Easiest way to display colored text in a textbox?

Easiest way to display colored text in a textbox?

Scheduled Pinned Locked Moved C / C++ / MFC
question
5 Posts 4 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.
  • G Offline
    G Offline
    generic_user_id
    wrote on last edited by
    #1

    I'm working with a text box (CEdit), but unfortunatly, there aren't any functions to change the text color. I would like to know what is the easiest way to make a text box with different lines of text in different colors. There are quite some syntax coloring edit boxes out there, but they have way too many features. Even a rich edit control (Working in a dialog) doesn't seem to support this easily. (you have to select parts of the text or something, then you can change a mask...) Maybe it can be done with OnCtlColor, but then I can only change the text color of the entire Dialog... Got any ideas?

    N C M 3 Replies Last reply
    0
    • G generic_user_id

      I'm working with a text box (CEdit), but unfortunatly, there aren't any functions to change the text color. I would like to know what is the easiest way to make a text box with different lines of text in different colors. There are quite some syntax coloring edit boxes out there, but they have way too many features. Even a rich edit control (Working in a dialog) doesn't seem to support this easily. (you have to select parts of the text or something, then you can change a mask...) Maybe it can be done with OnCtlColor, but then I can only change the text color of the entire Dialog... Got any ideas?

      N Offline
      N Offline
      Nish Nishant
      wrote on last edited by
      #2

      Griffith Sutherns wrote: Maybe it can be done with OnCtlColor, but then I can only change the text color of the entire Dialog... Nooo! You can check and see if nCtlColor is CTLCOLOR_EDIT if you want to change the color for every edit control or you can call GetDlgCtrlID on the pWnd which is a CWnd*, and chk if it's the specific edit control Nish


      The posting stats are now in PDF:- http://www.busterboy.org/codeproject/ Feel free to make your comments. Updated - May 04th, Saturday

      1 Reply Last reply
      0
      • G generic_user_id

        I'm working with a text box (CEdit), but unfortunatly, there aren't any functions to change the text color. I would like to know what is the easiest way to make a text box with different lines of text in different colors. There are quite some syntax coloring edit boxes out there, but they have way too many features. Even a rich edit control (Working in a dialog) doesn't seem to support this easily. (you have to select parts of the text or something, then you can change a mask...) Maybe it can be done with OnCtlColor, but then I can only change the text color of the entire Dialog... Got any ideas?

        C Offline
        C Offline
        Chris Losinger
        wrote on last edited by
        #3

        unfortunately, you'll need to use one of those syntax coloring edits, if you want to have multiple text colors in a single control. the basic CEdit only allows one color for text. it's hard to believe i know (my own syntax coloring editor implements the whole edit control thing from scratch - just to be able to color text) there are some classes that make rich edit use easier, especially if the text is read-only. and, even better, you could use an embedded instance of an HTML browser if your text is read-only (it's really quite simple). -c


        There ain't no second chance Against the thing with the forty eyes, girl

        Smaller Animals Software

        1 Reply Last reply
        0
        • G generic_user_id

          I'm working with a text box (CEdit), but unfortunatly, there aren't any functions to change the text color. I would like to know what is the easiest way to make a text box with different lines of text in different colors. There are quite some syntax coloring edit boxes out there, but they have way too many features. Even a rich edit control (Working in a dialog) doesn't seem to support this easily. (you have to select parts of the text or something, then you can change a mask...) Maybe it can be done with OnCtlColor, but then I can only change the text color of the entire Dialog... Got any ideas?

          M Offline
          M Offline
          Marc Richarme
          wrote on last edited by
          #4

          I'd solve this by using a ritchedit control, but instead of modifying the content, I'd generate some RTF (on the fly if necessary) with color codes in it and do a StreamIn.. it might sound complicated but it only takes a few lines of code and a simple callback function. Cheers! Marc.

          G 1 Reply Last reply
          0
          • M Marc Richarme

            I'd solve this by using a ritchedit control, but instead of modifying the content, I'd generate some RTF (on the fly if necessary) with color codes in it and do a StreamIn.. it might sound complicated but it only takes a few lines of code and a simple callback function. Cheers! Marc.

            G Offline
            G Offline
            generic_user_id
            wrote on last edited by
            #5

            Good idea. I'll try that Thanks for the feedback!

            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