Difference between revisions of "TToggleBox"

From Free Pascal wiki
Jump to navigationJump to search
(start adding "Usage")
(translate "Usage")
Line 19: Line 19:
 
A simple example:
 
A simple example:
  
-- in progress --[[User:Michl|Michl]] 13:46, 20 May 2014 (CEST)
+
* Create a new application and drop three TToggleBoxes on the form.
 
+
* Change the captions of ToggleBox1...3 to ''Red'', ''Green'' and ''Blue''.
* Erstellen Sie eine neue Anwendung und legen Sie auf dem Formular drei TToggleBoxen ab.
+
* Create a ''Onklick'' event handler for one of the ToggleBoxes, e.g. '''<code>procedure ToggleBox1Click(Sender: TObject);</code>''' and also connect the other ToggleBoxes with it:
* Ändern Sie die Captions von ToggleBox1..3 zu "Rot", "Gruen" und "Blau".
+
** Select ''ToggleBox1'' on your form.
* 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:
+
** Go in the Object Inspector on the tab events, select the ''OnClick'' event and click on the button [...].
** Wählen Sie ''ToggleBox1'' auf Ihrem Formular an.
+
** It creates the procedure ''ToggleBox1Click''.
** Gehen Sie in den Objektinspektor auf den Reiter Ereignisse, wählen Sie das Ereignis ''OnClick'' und klicken Sie auf den Button [...].
+
** Now select ''ToggleBox2'' on your form.
** Es wird die Procedure ''ToggleBox1Click'' erstellt.
+
** Go in the Object Inspector to the tab events, choose the ''OnClick'' event and select ''ToggleBox1Click'' in the adjacent combobox.
** Jetzt wählen Sie ''ToggleBox2'' auf Ihrem Formular an.
+
** Now on your form, select ''ToggleBox3'' and proceed as with ''ToggleBox2''.
** Gehen Sie in den Objektinspektor auf den Reiter Ereignisse, wählen Sie das Ereignis ''OnClick'' und wählen daneben in der Combobox ''ToggleBox1Click'' aus.
+
* Get the event handler ''OnClick'' of the ToggleBoxes the colors of the form, according to ''<ToggleBox>.Checked'', change:
** 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>
 
<syntaxhighlight>
 
procedure TForm1.ToggleBoxClick(Sender: TObject);
 
procedure TForm1.ToggleBoxClick(Sender: TObject);
Line 36: Line 34:
 
   aColor: TColor;  
 
   aColor: TColor;  
 
begin
 
begin
   aColor:=0;        //Hintergrundfarbe von Form1 wird entsprechend der Toggleboxen festgelegt
+
   aColor:=0;        //Background color of Form1 is set according to the Toggleboxes
 
   if ToggleBox1.Checked then aColor:=aColor + $0000FF;
 
   if ToggleBox1.Checked then aColor:=aColor + $0000FF;
 
   if ToggleBox2.Checked then aColor:=aColor + $00FF00;
 
   if ToggleBox2.Checked then aColor:=aColor + $00FF00;
 
   if ToggleBox3.Checked then aColor:=aColor + $FF0000;
 
   if ToggleBox3.Checked then aColor:=aColor + $FF0000;
   Color := aColor;  //die Änderung der Eigenschaft <Formular>.Color bewirkt ein Neuzeichnen des Formulars
+
   Color := aColor;  //the change of the property <Formular>.Color causes a redrawing of the form
 
end;  
 
end;  
 
</syntaxhighlight>
 
</syntaxhighlight>
* Starten Sie Ihr Programm, es sollte ungefähr so aussehen:
+
* Start your program, it should look something like:
  
 
[[image:ToggleBoxExample1.png]] -> [[image:ToggleBoxExample2.png]]
 
[[image:ToggleBoxExample1.png]] -> [[image:ToggleBoxExample2.png]]

Revision as of 21:29, 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:

  • Create a new application and drop three TToggleBoxes on the form.
  • Change the captions of ToggleBox1...3 to Red, Green and Blue.
  • Create a Onklick event handler for one of the ToggleBoxes, e.g. procedure ToggleBox1Click(Sender: TObject); and also connect the other ToggleBoxes with it:
    • Select ToggleBox1 on your form.
    • Go in the Object Inspector on the tab events, select the OnClick event and click on the button [...].
    • It creates the procedure ToggleBox1Click.
    • Now select ToggleBox2 on your form.
    • Go in the Object Inspector to the tab events, choose the OnClick event and select ToggleBox1Click in the adjacent combobox.
    • Now on your form, select ToggleBox3 and proceed as with ToggleBox2.
  • Get the event handler OnClick of the ToggleBoxes the colors of the form, according to <ToggleBox>.Checked, change:
procedure TForm1.ToggleBoxClick(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;
  • Start your program, it should look something like:

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)