UserGuide

Desktop Radio Button

From Xojo Documentation

Revision as of 15:02, 12 November 2019 by PLefebvre (talk | contribs) (Events)
Radio Button Library Icon

Radio Buttons are used to present the user with two or more choices, where only one of the choices can be selected. Selecting one Radio Button causes the Radio Button that is currently selected to become unselected. They are called Radio Buttons because they act just like the row of buttons for changing radio stations on car radios where pushing one button deselects the current radio station and selects the new station. Radio Buttons should always be displayed in groups of at least two.

If you have multiple sets of Radio Buttons on a Window, they should be grouped in a container, usually a Group Box. Other contains such as a Canvas, Rectangle or Container Control also work.

Refer to RadioButton in the Language Reference for details on all its events, properties and methods.

Below are the commonly used events and properties.

Events

Action

Called when the radio button is selected. This is not called for radio buttons that are deselected.

Properties

Caption

The text that displays beside the radio button. On macOS, this wraps if it is wider than the radio button width.

Value

The Value is True when the radio button is selected and False when it is not selected.

Handling Focus

On Windows, a radio button whose Value is True can get the focus when you tab through the controls. Once a radio button has the focus, the arrow keys can be used to move to other radio buttons, changing the selection.

Usage

Group Box with Radio Buttons

Since only a single radio button can have its Value set to True at one time, you will nearly always want to have your radio buttons grouped. The Group Box control is often used for this.

In the Action event handler, you will put the code that should run when the button is selected.

You can also select a radio button in your code by assign it to True. Doing so sets all other radio button values (in the group) to False.

MyRadioButton.Value = True

See Also

RadioButton class; UserGuide:Desktop Group Box topic