Question and Answer Database FAQ990D.txt Changing the background color of Text Category :Windows API Platform :All Product :All 32 bit 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; 7/16/98 4:31:28 PM
Last Modified: 01-SEP-99