Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Changing text background color in RichEdit Control

Posted on 1998-09-29
9
Medium Priority
?
1,349 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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
 
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 600 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

618 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