Solved

Changing text background color in RichEdit Control

Posted on 1998-09-29
9
1,106 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
A short film showing how OnPage and Connectwise integration works.

932 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

10 Experts available now in Live!

Get 1:1 Help Now