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 API SendMessage()
function, or the TRichEdit
's own Perform()
method, to send it an EM_SETCHARFORMAT
message, specifying a CHARFORMAT2
structure whose crBackColor
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.