[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Changing text background color in RichEdit Control

Posted on 1998-09-29
9
Medium Priority
?
1,393 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

872 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