- - * - WhiteUnicorn - * - -




* #WhiteUnicorn/ StartPage/ Documentation/DelphiFAQ >


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;



* #WhiteUnicorn/ StartPage/ Documentation/DelphiFAQ >



- - * - Anastasija aka WhiteUnicorn - * - - LJLiveJournal
PFPhotoFile