///方法一:还是用VCL,但是是动态生成的procedure TForm1.FormCreate(Sender: TObject); begin with TLabel.Create(Self) do begin Left := 50; Top := 50; Caption := 'HELLO'; Parent := Self; Visible := True; end; end; ///方法二:用Canvas的TextOut方法画procedure TForm1.FormPaint(Sender: TObject); begin Self.Canvas.TextOut(100, 100, 'HELLO'); end;///方法三:直接用API函数(与Canvas方法类似,略)
procedure TForm1.FormPaint(Sender: TObject); var DC: HDC; begin DC := Self.Canvas.Handle; SetTextColor(DC, clRed); SetBkMode(DC, TransParent); TextOut(DC, 50, 100, PAnsiChar('HELLO'), 5); end;
var Test : TLabel; begin Test := Tlabel.Create(Self); test.Caption := 'Hello world'; test.Parent := Self; test.Left := 100 ; test.Top := 100 ; end;
///方法一:还是用VCL,但是是动态生成的procedure TForm1.FormCreate(Sender: TObject);
begin
with TLabel.Create(Self) do begin
Left := 50;
Top := 50;
Caption := 'HELLO';
Parent := Self;
Visible := True;
end;
end;
///方法二:用Canvas的TextOut方法画procedure TForm1.FormPaint(Sender: TObject);
begin
Self.Canvas.TextOut(100, 100, 'HELLO');
end;///方法三:直接用API函数(与Canvas方法类似,略)
procedure TForm1.FormPaint(Sender: TObject);
var
DC: HDC;
begin
DC := Self.Canvas.Handle;
SetTextColor(DC, clRed);
SetBkMode(DC, TransParent);
TextOut(DC, 50, 100, PAnsiChar('HELLO'), 5);
end;
Test : TLabel;
begin
Test := Tlabel.Create(Self);
test.Caption := 'Hello world';
test.Parent := Self;
test.Left := 100 ;
test.Top := 100 ;
end;
在interface区,uses子句中,加上 StdCtrls
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
var
lb: TLabel;
begin
lb := TLabel.Create(Self);
lb.Parent := Self;
lb.Caption := 'lb.Caption';
lb.Left := 100;
lb.top := 100;
end;end.
Test : TLabel;
begin
Test := Tlabel.Create(Self);
test.Caption := 'Hello world';
test.Parent := Self;
test.Left := 100 ;
test.Top := 100 ;
end;这个简洁