VCL Controls: The Check Box |
|
Introduction |
|
From the developer standpoint, a check mark has two (Boolean) values: true or false (or TRUE or FALSE, or True or False). When a check mark is selected, its value is true; otherwise, its value is false. Those are the primary concerns you will have with check marks.A check mark is a special button and can be programmed as a regular button. Therefore, depending on your needs, you can display or hide it at will; you can enable and disable it as necessary; you can adjust its behavior depending on other controls on the same form or the same application. Check Box Properties If you are planning to have just one check box, from the Standard tab of the Component Palette, click the
CheckBox control and click on the desired section of the form or container. If you are planning to use more than one check box, you should first position a group control to your form, then add the desired
CheckBox controls.
When a check box is clicked, its Checked property has a value of true; otherwise, the values is false. Since the Checked property is a Boolean value, you can toggle its state based on an intermediary action from the program, the user, or the computer:
Probably the most important property of a check box is its caption, which is controlled by the Caption property. This can easily be set at design or runtime. The position of the caption is controlled by the Alignment property. By default, the check box caption is aligned to the right side of the check box:
To change the caption alignment of a check box, use the Alignment property of the Object Inspector. The values are
taRightJustify for the right alignment and the taLeftJustify. This property is set using the AllowGrayed property. In the Object Inspector, change the (Boolean) of the desired check box to true or false (the default). Programmatically, to set this property, assign it a true value (because otherwise the false value is set by default). At design time or when the user is interacting with your application, you can control the display of a check box using one of three states. Unlike being checked or unchecked, like the AllowGrayed property, you can set an intermediary that would help you and user know that the control’s condition cannot be definitely decided. This is set using the State property. This property, derived from the TCheckBoxState enumerator, allows you to set a check box as unchecked (the default) by assigning the cbUnchecked value; to definitely check it, set this property to cbChecked. As a 3rd alternative, you can assign it a cbGrayed value. Check Box Methods and Events The check box control has only its constructor and its destructor as methods. The constructor allows you to dynamically create the control. To do this, use the new operator to assign a TCheckBox object to the named instance of the control. You must also specify what control, namely the form owns the check box because the compiler wants to know “who” would clean after the object when the control is not used anymore:
If the check box will be hosted by a container other than the form, specify this as the parent:
If you do not have or cannot get a container at design time, you can also dynamically create one that would host the dynamic check boxes. Here is an example:
To create this control globally, that is, to make it accessible by more than one function, method or event, declare it in the private or public sections of the header file of the unit or object (control) that would “own” it. We have seen various examples of doing this already.
|
|
|
||
Home | Copyright © 2004-2007 FunctionX, Inc. | |
|