Difference between revisions of "TToggleBox"

From Lazarus wiki
Jump to navigationJump to search
(Preparation for translation)
(start adding "Usage")
Line 7: Line 7:
 
==Description==
 
==Description==
  
A labelled box capable of being checked or unchecked.
+
A labelled box capable of being checked or unchecked. It is similar to a [[TButton]], but it is enabled or disabled with a single click.
  
 
[[image:Comp_Standard_TToggleBox.png]]
 
[[image:Comp_Standard_TToggleBox.png]]
Line 13: Line 13:
 
==Usage==
 
==Usage==
  
in progress --[[User:Michl|Michl]] 20:50, 19 May 2014 (CEST)
+
To use a [[doc:lcl/stdctrls/ttogglebox.html|TToggleBox]] on a [[TForm/de|form]], you can simply select it on the Standard component pallet and place it by clicking on the form.<br>
 +
 
 +
Anywhere in your source code, you can check the status, whether active or inactive, by query '''<code>Status := <ToggleBox>.Checked;</code>'''. You can use ''Checked'' as a normal [[Boolean]]. Thus, even an assignment, '''<code><ToggleBox>.Checked := True;</code>''', is possible.<br>
 +
<br>
 +
A simple example:
 +
 
 +
-- in progress --[[User:Michl|Michl]] 13:46, 20 May 2014 (CEST)
 +
 
 +
* Erstellen Sie eine neue Anwendung und legen Sie auf dem Formular drei TToggleBoxen ab.
 +
* Ändern Sie die Captions von ToggleBox1..3 zu "Rot", "Gruen" und "Blau".
 +
* Erstellen Sie einen ''Onklick''-Eventhandler für eine der ToggleBoxen z.B. '''<code>procedure ToggleBox1Click(Sender: TObject);</code>''' und verbinden Sie die anderen ToggleBoxen ebenfalls mit dieser:
 +
** Wählen Sie ''ToggleBox1'' auf Ihrem Formular an.
 +
** Gehen Sie in den Objektinspektor auf den Reiter Ereignisse, wählen Sie das Ereignis ''OnClick'' und klicken Sie auf den Button [...].
 +
** Es wird die Procedure ''ToggleBox1Click'' erstellt.
 +
** Jetzt wählen Sie ''ToggleBox2'' auf Ihrem Formular an.
 +
** Gehen Sie in den Objektinspektor auf den Reiter Ereignisse, wählen Sie das Ereignis ''OnClick'' und wählen daneben in der Combobox ''ToggleBox1Click'' aus.
 +
** Jetzt wählen Sie ''ToggleBox3'' auf Ihrem Formular an und verfahren, wie eben mit ''ToggleBox2''.
 +
* Lassen Sie im Eventhandler ''OnClick'' der ToggleBoxen die Farben des Formulars, gemäß ''<ToggleBox>.Checked'', ändern:
 +
<syntaxhighlight>
 +
procedure TForm1.ToggleBoxClick(Sender: TObject);
 +
var
 +
  aColor: TColor;
 +
begin
 +
  aColor:=0;        //Hintergrundfarbe von Form1 wird entsprechend der Toggleboxen festgelegt
 +
  if ToggleBox1.Checked then aColor:=aColor + $0000FF;
 +
  if ToggleBox2.Checked then aColor:=aColor + $00FF00;
 +
  if ToggleBox3.Checked then aColor:=aColor + $FF0000;
 +
  Color := aColor;  //die Änderung der Eigenschaft <Formular>.Color bewirkt ein Neuzeichnen des Formulars
 +
end;
 +
</syntaxhighlight>
 +
* Starten Sie Ihr Programm, es sollte ungefähr so aussehen:
 +
 
 +
[[image:ToggleBoxExample1.png]] -> [[image:ToggleBoxExample2.png]]
 +
 
 +
==See also==
 +
 
 +
[[TButton]] - Usage of Buttons<br>
 +
[[TCheckBox]] - Usage of CheckBoxes<br>
 +
[[TRadioButton]] - Usage of RadioButtons<br>
  
 
{{LCL Components Footer |TMemo|TCheckBox}}
 
{{LCL Components Footer |TMemo|TCheckBox}}
Line 21: Line 59:
 
[[Category:LCL]]
 
[[Category:LCL]]
 
[[Category:Components]]
 
[[Category:Components]]
 +
--[[User:Michl|Michl]] 13:46, 20 May 2014 (CEST)

Revision as of 13:46, 20 May 2014

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

>> LCL Components >> TToggleBox

This page explains how to use the TToggleBox 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

A labelled box capable of being checked or unchecked. It is similar to a TButton, but it is enabled or disabled with a single click.

Comp Standard TToggleBox.png

Usage

To use a TToggleBox on a form, you can simply select it on the Standard component pallet and place it by clicking on the form.

Anywhere in your source code, you can check the status, whether active or inactive, by query Status := <ToggleBox>.Checked;. You can use Checked as a normal Boolean. Thus, even an assignment, <ToggleBox>.Checked := True;, is possible.

A simple example:

-- in progress --Michl 13:46, 20 May 2014 (CEST)

  • Erstellen Sie eine neue Anwendung und legen Sie auf dem Formular drei TToggleBoxen ab.
  • Ändern Sie die Captions von ToggleBox1..3 zu "Rot", "Gruen" und "Blau".
  • Erstellen Sie einen Onklick-Eventhandler für eine der ToggleBoxen z.B. procedure ToggleBox1Click(Sender: TObject); und verbinden Sie die anderen ToggleBoxen ebenfalls mit dieser:
    • Wählen Sie ToggleBox1 auf Ihrem Formular an.
    • Gehen Sie in den Objektinspektor auf den Reiter Ereignisse, wählen Sie das Ereignis OnClick und klicken Sie auf den Button [...].
    • Es wird die Procedure ToggleBox1Click erstellt.
    • Jetzt wählen Sie ToggleBox2 auf Ihrem Formular an.
    • Gehen Sie in den Objektinspektor auf den Reiter Ereignisse, wählen Sie das Ereignis OnClick und wählen daneben in der Combobox ToggleBox1Click aus.
    • Jetzt wählen Sie ToggleBox3 auf Ihrem Formular an und verfahren, wie eben mit ToggleBox2.
  • Lassen Sie im Eventhandler OnClick der ToggleBoxen die Farben des Formulars, gemäß <ToggleBox>.Checked, ändern:
procedure TForm1.ToggleBoxClick(Sender: TObject);
var
  aColor: TColor; 
begin
  aColor:=0;        //Hintergrundfarbe von Form1 wird entsprechend der Toggleboxen festgelegt
  if ToggleBox1.Checked then aColor:=aColor + $0000FF;
  if ToggleBox2.Checked then aColor:=aColor + $00FF00;
  if ToggleBox3.Checked then aColor:=aColor + $FF0000;
  Color := aColor;  //die Änderung der Eigenschaft <Formular>.Color bewirkt ein Neuzeichnen des Formulars
end;
  • Starten Sie Ihr Programm, es sollte ungefähr so aussehen:

ToggleBoxExample1.png -> ToggleBoxExample2.png

See also

TButton - Usage of Buttons
TCheckBox - Usage of CheckBoxes
TRadioButton - Usage of RadioButtons


Return To: LCL Components  — Previous: TMemo Next: TCheckBox


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


--Michl 13:46, 20 May 2014 (CEST)