Difference between revisions of "TToggleBox"
(start adding "Usage") |
(translate "Usage") |
||
Line 19: | Line 19: | ||
A simple example: | 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. '''<code>procedure ToggleBox1Click(Sender: TObject);</code>''' 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: |
− | ** | ||
− | * | ||
<syntaxhighlight> | <syntaxhighlight> | ||
procedure TForm1.ToggleBoxClick(Sender: TObject); | procedure TForm1.ToggleBoxClick(Sender: TObject); | ||
Line 36: | Line 34: | ||
aColor: TColor; | aColor: TColor; | ||
begin | begin | ||
− | aColor:=0; // | + | 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; // | + | Color := aColor; //the change of the property <Formular>.Color causes a redrawing of the form |
end; | end; | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | * | + | * 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.
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:
See also
TButton - Usage of Buttons
TCheckBox - Usage of CheckBoxes
TRadioButton - Usage of RadioButtons
Return To: LCL Components | — Previous: TMemo | Next: TCheckBox |
--Michl 13:46, 20 May 2014 (CEST)