Solved

rich edit text colors

Posted on 2000-03-06
8
445 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
Comment Utility
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
Comment Utility
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
Comment Utility
Lischke,

it doesnt seem to work, di u have any other suggestion?
thanks!
0
 
LVL 2

Expert Comment

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

"RichEdit1.SelLength := 100;"

Peter
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 10

Expert Comment

by:Lischke
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

744 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

9 Experts available now in Live!

Get 1:1 Help Now