Difference between revisions of "TCheckBox"
From Lazarus wiki
Jump to navigationJump to searchm |
|||
(3 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
{{TCheckBox}} | {{TCheckBox}} | ||
− | + | A '''TCheckBox''' [[image:tcheckbox.png]] is a component that provides a label with a box which can contain a check mark. The TCheckbox control is the standard checkbox. It is available fron the [[Standard tab]] of the [[Component Palette]]. When the TCheckBox is checked (☑) then checked property is [[True]] otherwise [[False]]. | |
+ | If property AllowGrayed is set to False (default value), the check box has only two possible states (property State): cbChecked and cbUnchecked. If AllowGrayed is set to True, the check box has three possible states: cbChecked, cbUnchecked and cbGrayed. | ||
− | + | [[image:TCheckBox-milk-sugar.png]] | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
==Usage== | ==Usage== | ||
− | |||
To use a [[doc:lcl/stdctrls/tcheckbox.html|TCheckBox]] on a form | To use a [[doc:lcl/stdctrls/tcheckbox.html|TCheckBox]] on a form | ||
− | # Click on the | + | # Click on the TCheckBox control on the standard toolbar. |
− | # Click on the form | + | # Click on the form, the checkbox is placed on the form. |
− | # Go to the | + | # Go to the Object Inspector. On the '''Properties''' tab, on the '''Name''' property, change the name of the control to something appropriate. |
# In the property '''checked''', if the default state of the checkbox is not unchecked, double click on the value to flip it from false to true. | # In the property '''checked''', if the default state of the checkbox is not unchecked, double click on the value to flip it from false to true. | ||
# There will be a label appearing to the right of this checkbox, usually set to something like its name, e.g. '''Checkbox1'''. To change the label displayed, go to the '''caption''' property, type in the desired text and press enter. | # There will be a label appearing to the right of this checkbox, usually set to something like its name, e.g. '''Checkbox1'''. To change the label displayed, go to the '''caption''' property, type in the desired text and press enter. | ||
# If for some reason you want the label to appear to the left of the checkbox, go to the property '''BidiMode''' and change the value of this property to '''bdLeftToRight'''. To restore it to the standard display, change this value to '''bdRightToLeft'''. | # If for some reason you want the label to appear to the left of the checkbox, go to the property '''BidiMode''' and change the value of this property to '''bdLeftToRight'''. To restore it to the standard display, change this value to '''bdRightToLeft'''. | ||
− | # If the checkbox simply stores a value, you're done. | + | # If the checkbox simply stores a value, you're done. If you need to have the checkbox do something when it's clicked, you need to add an event. To do that, click on the '''Events''' tab, click on the property '''OnClick''', then click on the button with three dots. You'll be taken to the code window and the handler for the OnClick event will be created. You can enter the code to be executed if this event occurs. |
− | # | + | # To change a checkbox's value in code, set its '''checked''' property to the value {{TF}} to indicate if the checkbox is checked or unchecked, respectively. |
+ | == See also== | ||
+ | * [[doc:lcl/stdctrls/tcheckbox.html|TCheckBox doc]] | ||
+ | * [[TCheckGroup]] | ||
+ | * [[TCheckListBox]] | ||
+ | * [[TLabel]] | ||
− | |||
{{LCL Components}} | {{LCL Components}} | ||
− | |||
− | |||
− | |||
− |
Latest revision as of 08:31, 21 January 2017
│
Deutsch (de) │
English (en) │
suomi (fi) │
français (fr) │
日本語 (ja) │
русский (ru) │
A TCheckBox is a component that provides a label with a box which can contain a check mark. The TCheckbox control is the standard checkbox. It is available fron the Standard tab of the Component Palette. When the TCheckBox is checked (☑) then checked property is True otherwise False. If property AllowGrayed is set to False (default value), the check box has only two possible states (property State): cbChecked and cbUnchecked. If AllowGrayed is set to True, the check box has three possible states: cbChecked, cbUnchecked and cbGrayed.
Usage
To use a TCheckBox on a form
- Click on the TCheckBox control on the standard toolbar.
- Click on the form, the checkbox is placed on the form.
- Go to the Object Inspector. On the Properties tab, on the Name property, change the name of the control to something appropriate.
- In the property checked, if the default state of the checkbox is not unchecked, double click on the value to flip it from false to true.
- There will be a label appearing to the right of this checkbox, usually set to something like its name, e.g. Checkbox1. To change the label displayed, go to the caption property, type in the desired text and press enter.
- If for some reason you want the label to appear to the left of the checkbox, go to the property BidiMode and change the value of this property to bdLeftToRight. To restore it to the standard display, change this value to bdRightToLeft.
- If the checkbox simply stores a value, you're done. If you need to have the checkbox do something when it's clicked, you need to add an event. To do that, click on the Events tab, click on the property OnClick, then click on the button with three dots. You'll be taken to the code window and the handler for the OnClick event will be created. You can enter the code to be executed if this event occurs.
- To change a checkbox's value in code, set its checked property to the value
True
orFalse
to indicate if the checkbox is checked or unchecked, respectively.
See also