Difference between revisions of "Documentation/DevGuide/Basic/Option Button"

From Apache OpenOffice Wiki
Jump to: navigation, search
(Initial author Sun Microsystems, Inc.)
 
 
(9 intermediate revisions by 6 users not shown)
Line 6: Line 6:
 
|NextPage=Documentation/DevGuide/Basic/Label Field
 
|NextPage=Documentation/DevGuide/Basic/Label Field
 
}}
 
}}
{{DISPLAYTITLE:Option Button}}
+
{{Documentation/DevGuideLanguages|Documentation/DevGuide/Basic/{{SUBPAGENAME}}}}
 +
{{DISPLAYTITLE:Option Button}}
 
An option button control <idl>com.sun.star.awt.UnoControlRadioButton</idl> is a simple switch with two states, that is selected by the user. Usually option buttons are used in groups to display several options, that the user may select. While option buttons and check boxes seem to be similar, selecting one option button deselects all the other option buttons in the same group.
 
An option button control <idl>com.sun.star.awt.UnoControlRadioButton</idl> is a simple switch with two states, that is selected by the user. Usually option buttons are used in groups to display several options, that the user may select. While option buttons and check boxes seem to be similar, selecting one option button deselects all the other option buttons in the same group.
  
{{Documentation/Note|Note, that option buttons that belong to the same group must have consecutive tab indices. Two groups of option buttons can be separated by any control with a tab index that is between the tab indices of the two groups.}}
+
{{Note|Note, that option buttons that belong to the same group must have consecutive tab indices. Two groups of option buttons can be separated by any control with a tab index that is between the tab indices of the two groups.}}
  
Usually a group box, or horizontal and vertical lines are used, because those controls visually group the option buttons together, but in principal this can be any control. There is no functional relationship between an option button and a group box. Option buttons are grouped through consecutive tab indices only.
+
Usually a group box, or horizontal and vertical lines are used, because those controls visually group the option buttons together, but in principle this can be any control. There is no functional relationship between an option button and a group box. Option buttons are grouped through consecutive tab indices only.
 
+
The state of an option button is accessed by the <code>State</code> property, where 0 is not checked and 1 is checked.
+
  
 +
The state of an option button is accessed by the <code>State</code> property of its Model, where 0 is not checked and 1 is checked.
 +
<syntaxhighlight lang="oobas">
 
   Function IsChecked( oOptionButtonModel As Object ) As Boolean
 
   Function IsChecked( oOptionButtonModel As Object ) As Boolean
 
       Dim bChecked As Boolean
 
       Dim bChecked As Boolean
Line 24: Line 25:
 
       IsChecked = bChecked
 
       IsChecked = bChecked
 
   End Function
 
   End Function
 +
</syntaxhighlight>
 +
The state of an option button is also returned by the <code>State</code> property of the control, where False is not checked and True is checked. The code is greatly simplified:
 +
<syntaxhighlight lang="oobas">
 +
  If oOptionButton.State Then
 +
    ' The option is checked
 +
  Else
 +
    ' The option is not checked
 +
  End If
 +
</syntaxhighlight>
  
 
{{PDL1}}
 
{{PDL1}}
[[Category: Basic and Dialogs]]
+
 
 +
[[Category:Documentation/Developer's Guide/Basic and Dialogs]]

Latest revision as of 12:35, 21 December 2020



An option button control com.sun.star.awt.UnoControlRadioButton is a simple switch with two states, that is selected by the user. Usually option buttons are used in groups to display several options, that the user may select. While option buttons and check boxes seem to be similar, selecting one option button deselects all the other option buttons in the same group.

Documentation note.png Note, that option buttons that belong to the same group must have consecutive tab indices. Two groups of option buttons can be separated by any control with a tab index that is between the tab indices of the two groups.

Usually a group box, or horizontal and vertical lines are used, because those controls visually group the option buttons together, but in principle this can be any control. There is no functional relationship between an option button and a group box. Option buttons are grouped through consecutive tab indices only.

The state of an option button is accessed by the State property of its Model, where 0 is not checked and 1 is checked.

  Function IsChecked( oOptionButtonModel As Object ) As Boolean
      Dim bChecked As Boolean
      If oOptionButtonModel.State = 1 Then
          bChecked = True
      Else
          bChecked = False
      End If
      IsChecked = bChecked
  End Function

The state of an option button is also returned by the State property of the control, where False is not checked and True is checked. The code is greatly simplified:

  If oOptionButton.State Then
     ' The option is checked
  Else
     ' The option is not checked
  End If
Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages