Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

rich edit text colors

Posted on 2000-03-06
8
Medium Priority
?
465 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
[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
  • 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

660 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