随笔 - 2146  文章 - 97 评论 - 11767 trackbacks - 253

本例效果图:


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.

posted on 2008-05-22 11:47  万一  阅读(...)  评论(...编辑  收藏