문제

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.

다른 팁

The MSDN on RTF specifies \cbN, where N is the color index.

Other searches suggest this is not supported by a lot of applications (OS X's native RTF viewer, Microsoft Word) so maybe you should look for a custom solution.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top