Solved

rich edit text colors

Posted on 2000-03-06
8
461 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
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 
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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Suggested Courses
Course of the Month9 days, 11 hours left to enroll

623 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