Solved

Changing text background color in RichEdit Control

Posted on 1998-09-29
9
1,127 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Strange code, can use it, but i cant figure out what it does. 3 61
Delphi 2 60
Find and Replace Stream with 0s 8 63
Graphics32 under Delphi 10.1 Berlin 2 68
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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

803 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