VCL.ToggleSwitch Sample

From RAD Studio Code Examples
Jump to: navigation, search

This is a sample that shows the use of the TToggleSwitch control.

Location

You can find the ToggleSwitch sample project at:

  • Start | Programs | Embarcadero RAD Studio Sydney | Samples and then navigate to either:
    • Object Pascal\VCL\ToggleSwitch
    • CPP\VCL\ToggleSwitch
  • Subversion Repository:
    • You can find Delphi and C++ code samples in GitHub Repositories. Search by name into the samples repositories according to your RAD Studio version.

Description

This application demonstrates the TToggleSwitch control and shows how to modify the caption text of the toggle switch.

The application uses the following controls:

  • TB: The toggle switch.
  • grpAlignment: Sets the alignment.
  • grpState: Toggles the state of the toggle switch.
  • grpColors: Sets the color of the switch and its parts.
  • grpstateCaptions: Edit controls that define the caption text.
  • chkReadOnly: Sets the ReadOnly property of the toggle switch.
  • chkShowStateCaptions: Specifes whether the toggle switch displays captions.
  • chkEnabled: Enables or disables the toggle switch.
  • cbxVclStyles: A combo box that allows you to change the style of the application. You can choose between any style that is active in the Application Appearance - Custom Styles options for this project.

How to Use the Sample

  1. Navigate to one of the locations given above and open:
    • Delphi: ToggleSwitch.dproj.
    • C++: ToggleSwitch.cbproj.
  2. Press F9 or choose Run > Run.
  3. Change the different options on the form and test the functionality of the toggle switch. Modify colors, caption text, alignment, and the state of the toggle switch.

Implementation

TToggleSwitchForm

On initialization, the FormCreate adds all the active styles to the cbxVclStyles combo box.

  • The application defines the following event handlers:
    • edtCaptionOffChange: Changes the CaptionOff property.
    • edtCaptionOnChange: Changes the CaptionOn property.
    • chkShowStateCaptionsClick: Changes the ShowStateCaption property.
    • grpAlignmentClick: Changes the Alignment property.
    • cbxThumbColorChange: Changes the ThumbColor property.
    • cbxFrameColorChange: Changes the FrameColor property.
    • cbxColorChange: Changes the Color property.
    • grpStateClick: Changes the State property.
    • chkReadOnlyClick: Changes the ReadOnly property.
    • cbxVclStylesChange: Sets the style for the application.
    • chkEnabledClick: Enables or disables the toggle switch.

Uses

See Also