TLabel
│
Deutsch (de) │
English (en) │
suomi (fi) │
français (fr) │
日本語 (ja) │
русский (ru) │
>> LCL Components >> TLabel
This page explains how to use the TLabel component. When I mention to click on something, unless I explicitly say to right-click, you always left-click on the item in question.
Description
Control to show static text, possibly in multiple lines.
Usage
A TLabel is one of the most basic components that you can put on a form. Most labels are the marking of other components, such as Edit fields, Memos, StringGrids and so on. TLabels provide a variety of events available to you but not required in most cases.
To change the default label Label of a new inserted TLabel on a form, you can proceed as follows:
- On your form with one click, select the TLabel.
- Go on properties in the Object Inspector tab.
- Select the property Caption and change it in the next edit field.
- In the same way, you can select the property Name and give the label a better name.
Of course, you can change the caption (the text displayed) during run time.
The following example demonstrates this:
- Create a new GUI application with the form Form1. Add this form still a TButton Button1 and a TLabel Label1 by selecting the appropriate components on the Standard Component Tab and clicking on Form1 (the label should be above the button).
- Create now a event handler for Button1, by simply double clicking on Button1.
- Insert following lines of code in the OnClick event handler of Button1:
procedure TForm1.Button1Click(Sender: TObject);
const Zaehler: Integer = 0; //Zähler um festzustellen, wie oft der Button geklickt wurde
begin
inc(Zaehler); //Erhöhe Zähler um 1
Label1.Caption:='Der Button wurde ' + //Schreibe den Text auf Caption von Label1
IntToStr(Zaehler) + ' mal geklickt';
end;
- Starten Sie Ihr Programm und testen Sie die Veränderung auf der Beschriftung (Caption) des Labels, mittels Klicken des Buttons.
Comments
Um einen mehrzeiligen Text darzustellen, müssen Sie an die entsprechende Stelle im anzuzeigenden String ein #13 als Zeilenumbruchsignal setzen.
Beispiel: Label1.Caption:='Das'#13'ist'#13'ein'#13'mehrzeiliger'#13'Text';
Return To: LCL Components | — Previous: TButton | Next: TEdit |
--Michl 21:42, 15 May 2014 (CEST)