Difference between revisions of "TToggleBox"

From Free Pascal wiki
Jump to navigationJump to search
Line 1: Line 1:
 
{{TToggleBox}}
 
{{TToggleBox}}
  
>> [[LCL Components]] >> TToggleBox<br/>
+
A '''TToggleBox''' [[image:ttogglebox.png]] is a two state labelled button that is enabled or disabled with a single click.
  
This page explains how to use the [[doc:lcl/stdctrls/ttogglebox.html|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.
+
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.
 
 
==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.
 
 
 
[[image:Comp_Standard_TToggleBox.png]]
 
 
 
==Usage==
 
 
 
To use a [[doc:lcl/stdctrls/ttogglebox.html|TToggleBox]] on a [[TForm|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===
 
===A simple example===
 
 
* Create a new application and drop three TToggleBoxes on the form.
 
* Create a new application and drop three TToggleBoxes on the form.
 
* Change the captions of ToggleBox1...3 to ''Red'', ''Green'' and ''Blue'' and it names to ''tbRed'', ''tbGreen'' und ''tbBlue''.
 
* Change the captions of ToggleBox1...3 to ''Red'', ''Green'' and ''Blue'' and it names to ''tbRed'', ''tbGreen'' und ''tbBlue''.
Line 43: Line 29:
 
===Use an event===
 
===Use an event===
  
The difference to the previous example is, the form would not be repainted by a button click, but already by clicking on one of the toggleboxes itself.<br>
+
The difference to the previous example is, the form would not be repainted by a button click, but already by clicking on one of the toggleboxes itself.
  
 
You can modify the previous example, by deleting the button and its ''OnClick'' event handler in the source code. But also easy, you can create a new example:
 
You can modify the previous example, by deleting the button and its ''OnClick'' event handler in the source code. But also easy, you can create a new example:
Line 69: Line 55:
  
 
==See also==
 
==See also==
 +
* [[doc:lcl/stdctrls/ttogglebox.html|TToggleBox doc]]
 +
* [[TButton]]
 +
* [[TCheckBox]]
 +
* [[TRadioButton]]
  
[[TButton]] - Usage of Buttons<br>
 
[[TCheckBox]] - Usage of CheckBoxes<br>
 
[[TRadioButton]] - Usage of RadioButtons<br>
 
 
{{LCL Components Footer |TMemo|TCheckBox}}
 
 
{{LCL Components}}
 
{{LCL Components}}
 
 
[[Category:LCL]]
 
[[Category:Components]]
 
--[[User:Michl|Michl]] 13:46, 20 May 2014 (CEST)
 

Revision as of 23:38, 23 July 2016

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

A TToggleBox ttogglebox.png is a two state labelled button that is enabled or disabled with a single click.

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

  • Create a new application and drop three TToggleBoxes on the form.
  • Change the captions of ToggleBox1...3 to Red, Green and Blue and it names to tbRed, tbGreen und tbBlue.
  • Add to your form a TButton and change its caption to Paint new and its name to btnPaint.
  • Create the OnClick event handler for the TButton: go in the Object Inspector tab events, select the OnClick event and the [...] button or simple doubleclick it on the form.
  • Add following code in the event handler of btnPaint:
procedure TForm1.btnPaintClick(Sender: TObject);
var
  aColor: TColor;
begin
  aColor:=0;        //Background color of Form1 is set according to the Toggleboxes
  if tbRed.Checked   then aColor:=aColor + $0000FF;
  if tbGreen.Checked then aColor:=aColor + $00FF00;
  if tbBlue.Checked  then aColor:=aColor + $FF0000;
  Color := aColor;  //the change of the property <Formular>.Color causes a redrawing of the form
end;
  • Start your program, it should look something like:

ToggleBoxExample1.png -> ToggleBoxExample2.png

Use an event

The difference to the previous example is, the form would not be repainted by a button click, but already by clicking on one of the toggleboxes itself.

You can modify the previous example, by deleting the button and its OnClick event handler in the source code. But also easy, you can create a new example:

  • Create a new application and drop three TToggleBoxes on the form.
  • Change the captions of ToggleBox1...3 to Red, Green and Blue and it names to tbRed, tbGreen und tbBlue.
  • Create a OnChange event handler for one of the ToggleBoxes, e.g. TForm1.tbRedChange(Sender: TObject); and also connect the other ToggleBoxes with it:
    • Doubleclick tbRed on your form or select tbRed on your form and go in the Object Inspector on the tab events, select the OnChange event and click on the button [...].
    • It creates the procedure tbRedChange.
    • Now select tbGreen on your form.
    • Go in the Object Inspector to the tab events, choose the OnChange event and select tbRedChange in the adjacent combobox.
    • Now on your form, select tbBlue and proceed as with tbGreen.
  • Get the event handler OnChange of the ToggleBoxes the colors of the form, according to <ToggleBox>.Checked, change:
procedure TForm1.tbRedChange(Sender: TObject); 
var
  aColor: TColor; 
begin
  aColor:=0;        //Background color of Form1 is set according to the Toggleboxes
  if ToggleBox1.Checked then aColor:=aColor + $0000FF;
  if ToggleBox2.Checked then aColor:=aColor + $00FF00;
  if ToggleBox3.Checked then aColor:=aColor + $FF0000;
  Color := aColor;  //the change of the property <Formular>.Color causes a redrawing of the form
end;

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