我想不使用D7里面VCL 的Label控件 直接写代码,生成一个Label标签,运行后显示‘HELLO’如何实现?

解决方案 »

  1.   


    ///方法一:还是用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方法类似,略)
      

  2.   


    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;
      

  3.   

    var
      Test : TLabel;
    begin
      Test := Tlabel.Create(Self);
      test.Caption := 'Hello world';
      test.Parent := Self;
      test.Left := 100 ;
      test.Top := 100 ;
    end;
      

  4.   

    能发我一个直接能编译,运行的完整程序吗   我在编译的时候他老说我的TLabel 没有定义 系统里面没有TLabel 吗?  请大侠们给个直接能编译的代码 谢谢!
      

  5.   


    在interface区,uses子句中,加上 StdCtrls
      

  6.   

    unit Unit1;interfaceuses
      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.
      

  7.   

    呵呵,都完了啊,var 
      Test : TLabel; 
    begin 
      Test := Tlabel.Create(Self); 
      test.Caption := 'Hello world'; 
      test.Parent := Self; 
      test.Left := 100 ; 
      test.Top := 100 ; 
    end;这个简洁