Examples Delphi

Frequently Asked Questions
Changing the background color of Text
Question:
How can I change the background color of Text?
Answer:
Use the Windows API functions SetBkColor() and TextOut().
Example:
procedure TForm1.Button1Click(Sender: TObject);
var
OldTextColor : TColorRef;
OldBkColor : TColorRef;
OldBkMode : Integer;
begin
OldTextColor := SetTextColor(Form1.Canvas.Handle, RGB(0, 0, 255));
OldBkColor := SetBkColor(Form1.Canvas.Handle, RGB(255, 0, 0));
OldBkMode := SetBkMode(Form1.Canvas.Handle, OPAQUE);
TextOut(Form1.Canvas.Handle,
100, 100,
'Blue text on red Background',
27);
SetBkMode(Form1.Canvas.Handle, OldBkMode);
SetBkColor(Form1.Canvas.Handle, OldBkColor);
SetTextColor(Form1.Canvas.Handle, OldTextColor);
end;
Back To Faq Index
Borland Online
Trademarks & Copyright © 1998 Borland International, Inc. Last modified on 1-December-1998.