Easiest way to display colored text in a textbox?
-
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?
-
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?
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
-
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?
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
-
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?
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.
-
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.
Good idea. I'll try that Thanks for the feedback!