把文字输出到屏幕

本例效果图:

把文字输出到屏幕

unit Unit1;



interface



uses

  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

  Dialogs, StdCtrls;



type

  TForm1 = class(TForm)

    Button1: TButton;

    Button2: TButton;

    procedure Button1Click(Sender: TObject);

    procedure Button2Click(Sender: TObject);

  end;



var

  Form1: TForm1;



implementation



{$R *.dfm}



//把文字输出到屏幕

procedure TForm1.Button1Click(Sender: TObject);

var

  cvs: TCanvas;

  Rect: TRect;

  Str: string;

begin

  cvs := TCanvas.Create;

  cvs.Handle := GetDC(0);

  SetBkMode(cvs.Handle, TRANSPARENT);

  //cvs.Font.Name := '宋体';

  cvs.Font.Style := [fsBold, fsItalic];

  cvs.Font.Size := 48;

  Randomize;

  cvs.Font.Color := Random($FFFFFF);

  Rect := Screen.DesktopRect;

  Str := '万一的 Delphi 博客';

  cvs.TextRect(Rect, Str, [tfSingleLine, tfCenter, tfVerticalCenter]);

  cvs.Free;

end;



//刷新显示

procedure TForm1.Button2Click(Sender: TObject);

begin

  InvalidateRect(0, nil, False);

end;



end.


 
   

你可能感兴趣的:(屏幕)