Difference between revisions of "RadioButton"

From Xojo Documentation

 
(2 intermediate revisions by the same user not shown)
Line 10: Line 10:
  
 
<dynamicTable id="Events" super="RectControl" class="eventTable" title="Events" columns="3">
 
<dynamicTable id="Events" super="RectControl" class="eventTable" title="Events" columns="3">
{{Event | name=Action | description=Action()&#x0A;The RadioButton has been clicked.  }}
 
 
{{Event | name=GotFocus | description=GotFocus()&#x0A;The radio button has received the focus and has a selection marquee around its caption (Windows and Linux only) }}
 
{{Event | name=GotFocus | description=GotFocus()&#x0A;The radio button has received the focus and has a selection marquee around its caption (Windows and Linux only) }}
 
{{Event | name=LostFocus | description=LostFocus()&#x0A;The radio button has lost the focus and no longer has a selection marquee (Windows and Linux). }}
 
{{Event | name=LostFocus | description=LostFocus()&#x0A;The radio button has lost the focus and no longer has a selection marquee (Windows and Linux). }}
 
{{Event | name=MouseDown | params=x as [[Integer]],y as [[Integer]] | returntype=[[Boolean]] | description=MouseDown(x as Integer,y as Integer) as Boolean&#x0A;The mouse button was pressed inside the control's region at the location passed in to x,y. }}
 
{{Event | name=MouseDown | params=x as [[Integer]],y as [[Integer]] | returntype=[[Boolean]] | description=MouseDown(x as Integer,y as Integer) as Boolean&#x0A;The mouse button was pressed inside the control's region at the location passed in to x,y. }}
 
{{Event | name=MouseUp | params=x as [[Integer]], y as [[Integer]] | returntype=[[Boolean]] | description=MouseUp(x as Integer, y as Integer) as Boolean&#x0A;The mouse button was released inside the control's region at the location passed in to x,y.  }}
 
{{Event | name=MouseUp | params=x as [[Integer]], y as [[Integer]] | returntype=[[Boolean]] | description=MouseUp(x as Integer, y as Integer) as Boolean&#x0A;The mouse button was released inside the control's region at the location passed in to x,y.  }}
 +
{{Event | name=ValueChanged | description=ValueChanged()&#x0A;The value property was changed either by the user pressing the button or via code.  }}
 
</dynamicTable>
 
</dynamicTable>
  
Line 20: Line 20:
 
{{Property | name=Bold | type=Boolean | platform=all | description=( Boolean)&nbsp;&nbsp;Applies the bold style to the button caption. }}
 
{{Property | name=Bold | type=Boolean | platform=all | description=( Boolean)&nbsp;&nbsp;Applies the bold style to the button caption. }}
 
{{Property | name=Caption | type=String | platform=all | description=( String)&nbsp;&nbsp;The button's text. }}
 
{{Property | name=Caption | type=String | platform=all | description=( String)&nbsp;&nbsp;The button's text. }}
 +
{{Property | name=FontName | type=String | platform=all | description=( String)&nbsp;&nbsp;Name of the font used to display the button caption.  }}
 +
{{Property | name=FontSize | type=Single | platform=all | description=( Single)&nbsp;&nbsp;Size of the font used to display the button caption.  }}
 +
{{Property | name=FontUnit | description=( FontUnits)&nbsp;&nbsp;The units for the text size of the font used to display the button caption.}}
 
{{Property | name=Italic | type=Boolean | platform=all | description=( Boolean)&nbsp;&nbsp;Applies the italic style to the button caption. }}
 
{{Property | name=Italic | type=Boolean | platform=all | description=( Boolean)&nbsp;&nbsp;Applies the italic style to the button caption. }}
{{Property | name=TextFont | type=String | platform=all | description=( String)&nbsp;&nbsp;Name of the font used to display the button caption.  }}
 
{{Property | name=TextSize | type=Single | platform=all | modifiedinversion=2009r4 | description=( Single)&nbsp;&nbsp;Size of the font used to display the button caption.  }}
 
{{Property | name=TextUnit | description=( FontUnits)&nbsp;&nbsp;The units for the text size of the font used to display the button caption.}}
 
 
{{Property | name=Underline | type=Boolean | platform=all | description=( Boolean)&nbsp;&nbsp;Applies the underline style to the button caption. }}
 
{{Property | name=Underline | type=Boolean | platform=all | description=( Boolean)&nbsp;&nbsp;Applies the underline style to the button caption. }}
 
{{Property | name=Value | type=Boolean | platform=all | description=( Boolean)&nbsp;&nbsp;Gets or sets the value of the radio button: True if the RadioButton is checked and False if it is not checked }}
 
{{Property | name=Value | type=Boolean | platform=all | description=( Boolean)&nbsp;&nbsp;Gets or sets the value of the radio button: True if the RadioButton is checked and False if it is not checked }}
Line 32: Line 32:
  
 
==Notes==
 
==Notes==
If you enclose a group of radio button controls within a parent control (or just the parent window), other radio buttons are automatically deselected when the user clicks a radio button in the group.
+
If you enclose a group of radio button controls within a parent control (or just the parent window), other radio buttons are automatically deselected when the user presses a radio button in the group.
  
 
If you have more than one group of radio buttons in a window, each group should have its own parent control. RadioButtons within a group will be enabled and disabled automatically when the parent control is enabled/disabled. You can use controls such as [[GroupBox|GroupBoxes]], [[TabPanel|TabPanels]], [[PagePanel|PagePanels]], or even [[Canvas|Canvases]] as parent controls.  
 
If you have more than one group of radio buttons in a window, each group should have its own parent control. RadioButtons within a group will be enabled and disabled automatically when the parent control is enabled/disabled. You can use controls such as [[GroupBox|GroupBoxes]], [[TabPanel|TabPanels]], [[PagePanel|PagePanels]], or even [[Canvas|Canvases]] as parent controls.  
Line 45: Line 45:
 
In this code, the controls are all named "RadioButton1". RadioButton1's Action event is passed the parameter, "index As Integer". The parameter ''Index'' contains the value of Index for the RadioButton that was clicked. The event handler has this code:
 
In this code, the controls are all named "RadioButton1". RadioButton1's Action event is passed the parameter, "index As Integer". The parameter ''Index'' contains the value of Index for the RadioButton that was clicked. The event handler has this code:
 
<rbcode>
 
<rbcode>
Sub Action(index As Integer)
+
Sub Pressed(index As Integer)
   Label1.Text = "You chose radio button " + Str(index) + "."
+
   Label1.Value = "You chose radio button " + index.ToString + "."
 
End Sub
 
End Sub
 
</rbcode>
 
</rbcode>

Latest revision as of 16:10, 8 August 2019


For web apps, see RadioGroup.

Class (inherits from RectControl)

The standard radio button control used by desktop applications. RadioButtons are often placed within GroupBox controls.

Events
Closing GotFocus MouseMove
ConstructContextualMenu KeyDown MouseUp
ContextualMenuAction KeyUp MouseWheel
DragEnter LostFocus Opening
DragExit MouseDown ValueChanged
DragOver MouseEnter
DropObject MouseExit
Properties
Active fa-lock-32.png Italic Scope fa-lock-32.png
AllowAutoDeactivate Left TabIndex
AllowTabStop LockBottom Tooltip
Bold LockLeft Top
Caption LockRight Transparent
Enabled LockTop TrueWindow fa-lock-32.png
FontName MouseCursor Underline
FontSize MouseX fa-lock-32.png Value
FontUnit MouseY fa-lock-32.png Visible
Handle fa-lock-32.png Name fa-lock-32.png Width
Height PanelIndex Window fa-lock-32.png
Index fa-lock-32.png Parent
Methods
AcceptFileDrop AcceptTextDrop Invalidate
AcceptPictureDrop Close Refresh
AcceptRawDataDrop DrawInto SetFocus

Notes

If you enclose a group of radio button controls within a parent control (or just the parent window), other radio buttons are automatically deselected when the user presses a radio button in the group.

If you have more than one group of radio buttons in a window, each group should have its own parent control. RadioButtons within a group will be enabled and disabled automatically when the parent control is enabled/disabled. You can use controls such as GroupBoxes, TabPanels, PagePanels, or even Canvases as parent controls.

If the Caption property contains an ampersand character, it will display only if it is preceded by another ampersand character. This is done to make applications on all platforms behave consistently.

Sample Code

Here's how to set up RadioButtons using a GroupBox.

Three RadioButtons are set up as a Control Set and are placed within a GroupBox.

In this code, the controls are all named "RadioButton1". RadioButton1's Action event is passed the parameter, "index As Integer". The parameter Index contains the value of Index for the RadioButton that was clicked. The event handler has this code:

Sub Pressed(index As Integer)
Label1.Value = "You chose radio button " + index.ToString + "."
End Sub

To select a RadioButton in a Control Set, you use its Index property in code to refer to the RadioButton whose value you want to set. For example, the following line selects the second RadioButton from code.

RadioButton1(1).Value = True

See Also

GroupBox, PagePanel, TabPanel controls