I have a TRichEdit control containing source code. I want to set the background color of a single line.
I know how to set the text color, but isn't there a way to set the background color as well? I'm not talking about the entire background colour for the whole control, only how to change one single line.
Do I really have to write a custom control to do this?
There is no
TRichEdit
property for setting the background color of individual characters/lines. However, you can use the Win32 APISendMessage()
function, or theTRichEdit
's ownPerform()
method, to send it anEM_SETCHARFORMAT
message, specifying aCHARFORMAT2
structure whosecrBackColor
field is set to the desired color. You can apply formatting to existing characters by highlighting them first, or you can apply formatting to the current caret position if there is no selection.