How to change background color of margins in RichEdit?

575 views Asked by At

I used the following code to add margins to RichEdit. How can I change their background color?

procedure TForm1.Button1Click(Sender: TObject);
var
   LRect: TRect;
begin
   LRect := RichEdit1.ClientRect;
   InflateRect(LRect, -25, -25); 
   RichEdit1.Perform(EM_SETRECT, 0, Integer(@LRect));
end;
2

There are 2 answers

0
Remy Lebeau On

EM_SETRECT merely tells the RichEdit the rectangle where it is allowed to render its text. To change the background color of the margin you are reserving space for, you will have to subclass the RichEdit to handle WM_PAINT messages directly, then you can draw whatever you want in that space.

0
DavidK On

I'm not sure if this will work, but you could send an EM_SETEDITSTYLE message to set SES_EXTENDBACKCOLOR, which I have used in the past - this causes whatever the background colour is to extend into the margins. See this MSDN page for a bit more detail.