Solved

Changing text background color in RichEdit Control

Posted on 1998-09-29
9
1,085 Views
Last Modified: 2013-11-22
Does anyone know how to change the background color in a richedit control for selected text? I don't want all the background changed, just the background for selected text.

Thanks, DG
0
Comment
Question by:horushorus
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 2

Expert Comment

by:kjteng
ID: 1341226
You can use SetSysColor to change the system color setting;

procedure TForm1.Button1Click(Sender: TObject);
var aColor: array[0..0] of integer; i: word;
begin
  aColor[0] := COLOR_HIGHLIGHT;
  i := clYellow; { or any other color}
  w := GetSysColor(COLOR_HIGHLIGHT);
  SetSysColors(1, aColor, i)
end;

w is a global variable of word type. remember to set the syscolor back to w when you exit the edit box.
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1341227
You could also use the OnDeactivate() to change the syscolor back to the original and OnActivate() of the form  to return it to your prefered color...

Regards,
Viktor Ivanov
0
 
LVL 5

Expert Comment

by:scrapdog
ID: 1341228
SetSysColor changes the highlight color of the whole system, in ALL other programs.
0
 

Author Comment

by:horushorus
ID: 1341229
I may not have made myself clear... once the text has been deselected, I want the text background a different color to the rest of the text.

So if I had this text in a richedit control, I want to change the background color of certain text so that it stands out - much like the highlight marker function in MS Word.

Thanks,
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 2

Expert Comment

by:kjteng
ID: 1341230
What is the problem now?
0
 
LVL 1

Expert Comment

by:duke_n
ID: 1341231
No one steals our chicks...
 And lives...
(sorry, couldn't resist).

this is very simple:

procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
richedit1.SelAttributes.Color:=clred;
end;

0
 

Author Comment

by:horushorus
ID: 1341232
I wish it was just this simple!
This just changes the color of the font...not the background.
0
 
LVL 1

Expert Comment

by:duke_n
ID: 1341233
Hey there is Trichedit98 component out there for a while already.
download it from http://www.torry.webnorth.com/ or http://sunsite.icm.edu.pl/delphi/.it has the needed property and lots of other interesting things, like multiundo.

procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
richedit981.SelAttributes.BackColor:=clred;
end;

0
 
LVL 1

Accepted Solution

by:
duke_n earned 200 total points
ID: 1341234
Do not hurry to reject my answer!
There is Trichedit98 component out there for a while already.
download it from http://www.torry.webnorth.com/ or http://sunsite.icm.edu.pl/delphi/.it has the needed property and lots of other interesting things, like multiundo.

procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
richedit981.SelAttributes.BackColor:=clred;
end;

0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now