Difference between revisions of "TLabel"

From Lazarus wiki
Jump to navigationJump to search
(Translation)
m (Fixed syntax highlighting)
 
(9 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
{{TLabel}}
 
{{TLabel}}
  
>> [[LCL Components]] >> TLabel<br/>
+
'''TLabel''' [[image:tlabel.png]] is a component that creates a text-item with one or more lines on another component. A TLabel is a descendant of [[TGraphicControl]] and is available under the [[Standard tab]] of the [[Component Palette]].
 
 
This page explains how to use the [http://lazarus-ccr.sourceforge.net/docs/lcl/stdctrls/tlabel.html 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.
 
 
 
[[image:Comp_Standard_TLabel.png]]
 
  
 
==Usage==
 
==Usage==
 +
A TLabel is one of the most basic components that can be used on [[TForm|forms]]. Most labels are the marking of other components, such as [[TEdit|Edit fields]], [[TMemo|Memos]], [[TStringGrid|StringGrids]] and so on. TLabels provide a variety of events available to you but not required in most cases.
  
A TLabel is one of the most basic components that you can put on a [[TForm|form]]. Most labels are the marking of other components, such as [[TEdit|Edit fields]], [[TMemo|Memos]], [[TStringGrid|StringGrids]] and so on. TLabels provide a variety of events available to you but not required in most cases.
+
You can add a label to your form, by clicking the TLabel (text symbol Abc) on the Standard component palette and place it with a click on your form.
  
 
To change the default label ''Label'' of a new inserted TLabel on a form, you can proceed as follows:
 
To change the default label ''Label'' of a new inserted TLabel on a form, you can proceed as follows:
Line 22: Line 15:
  
 
==Change caption at run time==
 
==Change caption at run time==
 
 
Of course, you can change the caption (the text displayed) during run time.
 
Of course, you can change the caption (the text displayed) during run time.
  
Line 29: Line 21:
 
* Create now a [[Event_order|event handler]] for ''Button1'', by simply double clicking on ''Button1''.
 
* Create now a [[Event_order|event handler]] for ''Button1'', by simply double clicking on ''Button1''.
 
* Insert following lines of code in the OnClick event handler of ''Button1'':
 
* Insert following lines of code in the OnClick event handler of ''Button1'':
<syntaxhighlight>
+
<syntaxhighlight lang=pascal>
 
procedure TForm1.Button1Click(Sender: TObject);
 
procedure TForm1.Button1Click(Sender: TObject);
 
const Cnt: Integer = 0;                    //Counter to determine how many times the button has been clicked
 
const Cnt: Integer = 0;                    //Counter to determine how many times the button has been clicked
Line 41: Line 33:
  
 
==Comments==
 
==Comments==
 +
To represent a multiline text, you need to insert at the appropriate place in the string a ''[[End of Line|LineEnding]]'' as a word wrap signal.
 +
Example:
 +
<syntaxhighlight lang=pascal>
 +
Label1.Caption := 'This' + LineEnding + 'is' + LineEnding + 'a' + LineEnding + 'multiline' + LineEnding + 'text';
 +
</syntaxhighlight>
  
To represent a multiline text, you need to insert at the appropriate place in the string a '''#13''' as a word wrap signal.<br>
+
==See also==
Example: '''<code>Label1.Caption:='This'#13'is'#13'a'#13'multiline'#13'text';</code>'''
+
* [[doc:/lcl/stdctrls/tlabel.html|TLabel doc]]
 
+
* [[TStaticText]]
  
{{LCL Components Footer|TButton|TEdit}}
 
 
{{LCL Components}}
 
{{LCL Components}}
 
 
[[Category:LCL]]
 
[[Category:Components]]
 
--[[User:Michl|Michl]] 21:42, 15 May 2014 (CEST)
 

Latest revision as of 07:14, 1 March 2020

Deutsch (de) English (en) suomi (fi) français (fr) русский (ru)

TLabel tlabel.png is a component that creates a text-item with one or more lines on another component. A TLabel is a descendant of TGraphicControl and is available under the Standard tab of the Component Palette.

Usage

A TLabel is one of the most basic components that can be used on forms. 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.

You can add a label to your form, by clicking the TLabel (text symbol Abc) on the Standard component palette and place it with a click on your form.

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.

Change caption at run time

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 Cnt: Integer = 0;                     //Counter to determine how many times the button has been clicked
begin
  inc(Cnt);                                 //Increment the counter by 1
  Label1.Caption:='Button was clicked ' +   //Write the text on the caption of Label1
    IntToStr(Cnt) + ' times';
end;
  • Start your program and test the change of the label caption by clicking the button.

Comments

To represent a multiline text, you need to insert at the appropriate place in the string a LineEnding as a word wrap signal. Example:

Label1.Caption := 'This' + LineEnding + 'is' + LineEnding + 'a' + LineEnding + 'multiline' + LineEnding + 'text';

See also


LCL Components
Component Tab Components
Standard TMainMenu • TPopupMenu • TButton • TLabel • TEdit • TMemo • TToggleBox • TCheckBox • TRadioButton • TListBox • TComboBox • TScrollBar • TGroupBox • TRadioGroup • TCheckGroup • TPanel • TFrame • TActionList
Additional TBitBtn • TSpeedButton • TStaticText • TImage • TShape • TBevel • TPaintBox • TNotebook • TLabeledEdit • TSplitter • TTrayIcon • TControlBar • TFlowPanel • TMaskEdit • TCheckListBox • TScrollBox • TApplicationProperties • TStringGrid • TDrawGrid • TPairSplitter • TColorBox • TColorListBox • TValueListEditor
Common Controls TTrackBar • TProgressBar • TTreeView • TListView • TStatusBar • TToolBar • TCoolBar • TUpDown • TPageControl • TTabControl • THeaderControl • TImageList • TPopupNotifier • TDateTimePicker
Dialogs TOpenDialog • TSaveDialog • TSelectDirectoryDialog • TColorDialog • TFontDialog • TFindDialog • TReplaceDialog • TTaskDialog • TOpenPictureDialog • TSavePictureDialog • TCalendarDialog • TCalculatorDialog • TPrinterSetupDialog • TPrintDialog • TPageSetupDialog
Data Controls TDBNavigator • TDBText • TDBEdit • TDBMemo • TDBImage • TDBListBox • TDBLookupListBox • TDBComboBox • TDBLookupComboBox • TDBCheckBox • TDBRadioGroup • TDBCalendar • TDBGroupBox • TDBGrid • TDBDateTimePicker
Data Access TDataSource • TCSVDataSet • TSdfDataSet • TBufDataset • TFixedFormatDataSet • TDbf • TMemDataset
System TTimer • TIdleTimer • TLazComponentQueue • THTMLHelpDatabase • THTMLBrowserHelpViewer • TAsyncProcess • TProcessUTF8 • TProcess • TSimpleIPCClient • TSimpleIPCServer • TXMLConfig • TEventLog • TServiceManager • TCHMHelpDatabase • TLHelpConnector
Misc TColorButton • TSpinEdit • TFloatSpinEdit • TArrow • TCalendar • TEditButton • TFileNameEdit • TDirectoryEdit • TDateEdit • TTimeEdit • TCalcEdit • TFileListBox • TFilterComboBox • TComboBoxEx • TCheckComboBox • TButtonPanel • TShellTreeView • TShellListView • TXMLPropStorage • TINIPropStorage • TJSONPropStorage • TIDEDialogLayoutStorage • TMRUManager • TStrHolder
LazControls TCheckBoxThemed • TDividerBevel • TExtendedNotebook • TListFilterEdit • TListViewFilterEdit • TLvlGraphControl • TShortPathEdit • TSpinEditEx • TFloatSpinEditEx • TTreeFilterEdit • TExtendedTabControl •
RTTI TTIEdit • TTIComboBox • TTIButton • TTICheckBox • TTILabel • TTIGroupBox • TTIRadioGroup • TTICheckGroup • TTICheckListBox • TTIListBox • TTIMemo • TTICalendar • TTIImage • TTIFloatSpinEdit • TTISpinEdit • TTITrackBar • TTIProgressBar • TTIMaskEdit • TTIColorButton • TMultiPropertyLink • TTIPropertyGrid • TTIGrid
SQLdb TSQLQuery • TSQLTransaction • TSQLScript • TSQLConnector • TMSSQLConnection • TSybaseConnection • TPQConnection • TPQTEventMonitor • TOracleConnection • TODBCConnection • TMySQL40Connection • TMySQL41Connection • TMySQL50Connection • TMySQL51Connection • TMySQL55Connection • TMySQL56Connection • TMySQL57Connection • TSQLite3Connection • TIBConnection • TFBAdmin • TFBEventMonitor • TSQLDBLibraryLoader
Pascal Script TPSScript • TPSScriptDebugger • TPSDllPlugin • TPSImport_Classes • TPSImport_DateUtils • TPSImport_ComObj • TPSImport_DB • TPSImport_Forms • TPSImport_Controls • TPSImport_StdCtrls • TPSCustomPlugin
SynEdit TSynEdit • TSynCompletion • TSynAutoComplete • TSynMacroRecorder • TSynExporterHTML • TSynPluginSyncroEdit • TSynPasSyn • TSynFreePascalSyn • TSynCppSyn • TSynJavaSyn • TSynPerlSyn • TSynHTMLSyn • TSynXMLSyn • TSynLFMSyn • TSynDiffSyn • TSynUNIXShellScriptSyn • TSynCssSyn • TSynPHPSyn • TSynTeXSyn • TSynSQLSyn • TSynPythonSyn • TSynVBSyn • TSynAnySyn • TSynMultiSyn • TSynBatSyn • TSynIniSyn • TSynPoSyn
Chart TChart • TListChartSource • TRandomChartSource • TUserDefinedChartSource • TCalculatedChartSource • TDbChartSource • TChartToolset • TChartAxisTransformations • TChartStyles • TChartLegendPanel • TChartNavScrollBar • TChartNavPanel • TIntervalChartSource • TDateTimeIntervalChartSource • TChartListBox • TChartExtentLink • TChartImageList
IPro TIpFileDataProvider • TIpHtmlDataProvider • TIpHttpDataProvider • TIpHtmlPanel
Virtual Controls TVirtualDrawTree • TVirtualStringTree • TVTHeaderPopupMenu