Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Different color for different text 1

Status
Not open for further replies.

eladna

Programmer
Dec 11, 2002
17
IL
Hi
Does somebody know how to draw characters in different colors at RichEdit?
 
At its simplest you set SelAttributes:
Code:
procedure TForm1.Button1Click(Sender: TObject);
begin
  RichEdit1.SelAttributes.Color := clRed;
  RichEdit1.Lines.Add( 'This is red');
  RichEdit1.SelAttributes.Color := clBlue;
  RichEdit1.Lines.Add( 'This is blue');
end;

Andrew
Hampshire, UK
 
Thank you Towerbase, that was very helpful.
But do you have an elegant way to change a specific word's color in a given text?
 
It would help if you could give an example of what you want to save me guessing but the following would change the word brown to Aqua (there isn't a clBrown colour).
Code:
procedure TForm1.Button1Click(Sender: TObject);
begin
  with RichEdit1 do begin
    Lines.Text := 'The quick brown fox jumps right over the lazy dog';
    SelStart := Pos ( 'brown', Lines.Text ) - 1;
    SelLength := Length( 'brown' );
    SelAttributes.Color := clAqua;
  end;
end;

Andrew
Hampshire, UK
 
Hi Andrew
Well the thing I'm trying to do is to make an Editor window for C programming, and I would like that words like "if" and "while" and so long will be bold or in different color.
 
There are lots of good editors already for C and other programming languages which highlight keywords. Some are freeware.

Why do you need to develop your own?



Andrew
Hampshire, UK
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top