View Full Version : Adding TLabel to form - Noobie Delphi User
new person
08-04-2005, 05:54 PM
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
Harry Hunt
08-04-2005, 06:08 PM
Off the back of my head
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;
new person
08-04-2005, 09:51 PM
thanks! :)
new user
08-04-2005, 10:21 PM
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
Harry Hunt
09-04-2005, 09:19 AM
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
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;
Upon creating the label
with TLabel.Create(Form1)
begin
...
OnClick := MyEvent;
...
end;
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.