Solved

rich edit text colors

Posted on 2000-03-06
8
453 Views
Last Modified: 2010-04-04
I wanted to have multiple colors on each line of my rich edit, how do i do this?

example.

'Hi there everyone!'
- I want 'Hi' to appear as blue and 'everyone' to appear in red.
How do i do this?
0
Comment
Question by:jchua
  • 2
  • 2
  • 2
  • +2
8 Comments
 
LVL 10

Expert Comment

by:Lischke
ID: 2586801
Select the text with:

  RichEdit1.SelStart := 100;
  RichEdit1.SelLenght := 100;

and then set the text attributes of the selected text like:

  RichEdit1.SelAttributes.Color := clRed;

Ciao, Mike
0
 
LVL 2

Expert Comment

by:PeterLarsen
ID: 2586808
I dont think it's possible to change the background color in TRichedit.
Take a look into the demos : "...borland\delphiX\demos\richedit".
Peter
0
 

Author Comment

by:jchua
ID: 2586865
Lischke,

it doesnt seem to work, di u have any other suggestion?
thanks!
0
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!

 
LVL 2

Expert Comment

by:PeterLarsen
ID: 2586925
Mike's sample change the foreground color - and except from the spelling - it will change the foreground color.. :-)

"RichEdit1.SelLength := 100;"

Peter
0
 
LVL 10

Expert Comment

by:Lischke
ID: 2586956
Peter,

yes, the forground color is changed with my code (despite the spelling error of "...Length"), but the question does not state about foreground or background colors. Just colors.

jchua,

WHAT does not work? Does the code start your browser or does the text line appear in green, although you specified red, or what else?

Ciao, Mike
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 2587004
hi all,

an easy sample

procedure TForm1.Button1Click(Sender: TObject);
begin
  richedit1.Selstart := 0;
  Richedit1.SelAttributes.Color := clred;
  Richedit1.SetSelTextBuf('Hi');
  richedit1.Selstart := Length(Richedit1.Lines[0]);
  Richedit1.SelAttributes.Color := clBlack;
  Richedit1.SetSelTextBuf(' there ');
  richedit1.Selstart := Length(Richedit1.Lines[0]);
  Richedit1.SelAttributes.Color := clBlue;
  Richedit1.SetSelTextBuf('everyone');

end;

meikl
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 2587041
just the same sample
except the colororder is now correct and now using the seltext-property instead of the setseltextbuf-method

procedure TForm1.Button1Click(Sender: TObject);
begin
  richedit1.Lines.Clear;
  richedit1.Selstart := 0;
  Richedit1.SelAttributes.Color := clBlue;
  Richedit1.SelText := 'Hi';
  richedit1.Selstart := Length(Richedit1.Text);
  Richedit1.SelAttributes.Color := clBlack;
  Richedit1.SelText := ' there ';
  richedit1.Selstart := Length(Richedit1.Text);
  Richedit1.SelAttributes.Color := clred;
  Richedit1.SelText := 'everyone';
end;

meikl
0
 
LVL 1

Accepted Solution

by:
halser earned 50 total points
ID: 2675911
The TRichEdit class in Delphi (D2 thru 5) implements a Richedit version 1 and this control does not support different background colors.

If you want to set the BACKGROUND color of the text in a richedit, you need at least a Richedit version 2 (the latest - version 3 - comes with W2K or Office2000). The DLL name of both - Richedit version 2 and version 3 is "Riched20.dll" and must be located in your \system directory.

That's the DLL part. Further you must implement the new functionality in Delphi. Luckily, there are already freeware implementations available.

Freeware implementation of Riched20.DLL (version 2): "Richedit98" from Alexander Obukhov. To download it, go to http://www.delphipages.com and search for "Richedit98".

Freeware implementation of Riched20.DLL (version 3): this is rather a tutorial by Robert Dunn. His home page is
http://home.att.net/~robertdunn/Yacs.html#RichEditPapers

Alex
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

679 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