Results 1 to 5 of 5

Thread: Adding TLabel to form - Noobie Delphi User

  1. #1
    new person
    Guest

    Adding TLabel to form - Noobie Delphi User

    Hi, im kind of new to delphi and i have a small problem.
    i would like it so when you click a button on the botton of the screen, a Tlabel would appear at the top of the screen, and if you click it again, another would appear below it, and so on.

    ive tried this myself a few times, but i dont have a clue and just get errors.

    thanks alot

  2. #2

    Re: Adding TLabel to form - Noobie Delphi User

    Off the back of my head

    [pascal]
    var
    LastLabelIndex: Integer;

    procedure Button1Click(Sender: TObject);
    begin
    with TLabel.Create(Form1) do
    begin
    Parent := Form1;
    Caption := 'Hello World';
    Visible := True;
    Left := 10;
    Top := LastLabelIndex * 20;
    Name := 'NewLabel' + IntToStr(LastLabelIndex);
    end;

    Inc(LastLabelIndex);
    end;
    [/pascal]
    Ask me about the xcess game development kit

  3. #3
    new person
    Guest

    thanks!

    thanks!

  4. #4
    new user
    Guest

    new question

    sorry for bein a bother, but how could i make it so when i clicked on one of the labels, something would happen like:
    showmessage('hello')
    thanks again

  5. #5

    Re: new question

    Quote Originally Posted by new user
    sorry for bein a bother, but how could i make it so when i clicked on one of the labels, something would happen like:
    showmessage('hello')
    thanks again
    [pascal]TForm1 = class(TForm)
    private
    procedure MyEvent(Sender: TObject);
    public
    ...
    end;

    procedure TForm1.MyEvent(Sender: TObject);
    begin
    if Sender is TLabel begin
    ShowMessage((Sender as TLabel).Caption);
    end;
    end;
    [/pascal]

    Upon creating the label

    [pascal]
    with TLabel.Create(Form1)
    begin
    ...
    OnClick := MyEvent;
    ...
    end;
    [/pascal]
    Ask me about the xcess game development kit

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •