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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Font color

Status
Not open for further replies.

Raven078

Programmer
Jan 14, 2003
22
0
0
NL
I want to change the font Fore- AND Back-groundcolor of an editable field. I tried it with an standard edit field and a richeditfield, but i can only find how to change the Foreground color. Does anybody have an idea how to do this?
 
text: Font.Color
background: Color (i.e Edit1.Color)

I dont want to change the complete background of the edit field. Only the backgroundcolor behind one or more letters.
 
If you want to draw characters in different colors, i think you will have to write your own paint routine. I cant think of a (standard) component that does that.

So you have to write something like:

Canvas.Brush.Color := clBlue;
Canvas.TextOut(x,y,'a');
Inc(x,Canvas.TextWidth('a'));

Canvas.Brush.Color := clRed;
Canvas.TextOut(x,y,'b');

etc ...

(Of course you would make some kind of function/class for ths)...

hope this helps....

- fruNNik
 
I did it like this:

procedure SetREBackColor(RE: TRichEdit; Color: TColor);
var
CharFormat2: TCharFormat2;
begin
FillChar(CharFormat2, SizeOf(CharFormat2), 0);
CharFormat2.cbSize := SizeOf(TCharFormat2);
CharFormat2.dwMask := CFM_BACKCOLOR;
CharFormat2.crBackColor := Color;
SendMessage(RE.Handle, EM_SETCHARFORMAT,
SCF_SELECTION, LPARAM(@CharFormat2));
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
if ColorDialog1.Execute then
SetREBackColor(RichEdit1,ColorDialog1.Color);
end;


Make sure you have Richedit in your uses clausule!

It has something to do with Richedit2, some dll files that are standard in the newer windows versions.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top