Toggle button control

<< Click to Display Table of Contents >>

Manual > Control Reference > Basics >

Toggle button control


Toggle button control (ToggleButton)

 

 

Toggle button control is a button that alternates between the states TRUE/FALSE (On/Off).

 

cr_0035

 

Toggle button control has two uses.

 

1) When you want to alternate between the TRUE/FALSE (On/Off) states with a single button operation.

2) By grouping Toggle button control, you can link multiple toggle buttons as a set for one operation.

This method is useful in situations where you want the operator to always select only one option from multiple options when operating the screen.

 

 

Switch between ON/OFF state for each button

 

Toggle button control can alternate between ON/OFF states in the same way as a button control with SwitchType ALTERNATE.

 

cr_0036

 

Bind each bit tag you want to switch ON/OFF to the SwitchValue of each button.

Each button operates independently.

 

Motor1 SwitchValue binding: INOUT:$M0

…

SwitchValue binding for Motor7: INOUT:$M7

 

 

 

Grouping buttons to select only one option from multiple options

 

By grouping multiple buttons, you can use it in situations where you want the user to select only one option from multiple options.

 

This sample is in the ToggleButton form of \\sample\control\controls.xml under "Grouped buttons for a number tag". In the sample, toggle buttons of Stop/Motor1/…/Motor7 are grouped.

 

1) In this state, Motor2 is selected.

cr_0037

 

2) When the operator selects Motor3, the Motor2 button is released and Moter3 becomes ON (pressed state).

cr_0038

 

The grouping steps are as follows:

 

1) Enter the name of each control you want to group into the Name property.

 

2) Choose a control from this group that will be the "parent." Choose one of the controls to be grouped as the parent.

 

3) In the GroupObject property of the parent control, set the names of the controls you want to group, separated by commas. At this time, you do not need to include the name of the parent control itself.

Example) GroupObject property: Motor1,Motor2,Motor3,Motor4,Motor5,Motor6,Motor7

 

4) Set the GroupThisValue property for each control to be grouped. GroupThisValue is the value used to identify which button in the group is pressed. Therefore, set a unique value for each control.

example)

GroupThisValue property of the Stop button: 0

GroupThisValue property of the Motor1 button: 1

…

GroupThisValue property of the Motor7 button: 7

 

5) Bind the tag that you want to notify when the switch is toggled to the GroupValue property of the parent control.

 

This binding allows you to change the tag's value (e.g. 0,1,2...) depending on the switch operation.

When a button in a group is pressed, the value of this property changes in real time according to the setting value of the GroupThisValue property assigned to that button.

In this example, when Motor2 is pressed, the parent control's GroupValue will be 2. When Motor5 is pressed, the GroupValue will be 5.

Note that the GroupValue property is read-only and is only displayed in the Bindings tab. When GroupValue changes, the OnGroupValueChanged event occurs.

 

 

Grouping allows turning on only one bit tag from multiple bit tags

 

You can group multiple buttons and turn on only one of the bit tags. All tags other than the bit tag that is turned on will be turned off.

 

For example, prepare three buttons (BitTag1/BitTag2/BitTag3) and group them following the steps on the previous page, "Grouping buttons and allowing users to select only one from multiple options."

The difference is that in step (5), instead of binding to the parent's GroupValue property, we bind to the SwitchValue of Toggle button control.

SwitchValue is the same as Button control, which is TRUE when the button is pressed and FALSE when it is not pressed.

 

cr_0039

 

 

Switch the state of one bit tag with two buttons

 

By grouping the two buttons, you can also switch the bit tag ON/OFF.

The setup procedure is the same as on the previous page, "Group and select only one from multiple options."

 

cr_0040

 

 

About the initial value of GroupValue when not binding

 

When grouping without binding, the initial value of GroupValue is -1.

If you want to set the initial value to a value other than -1, write the following in the parent control's OnInitialize event.

 

hmtoggle_plus1Example