Export (0) Print
Expand All

RadioButton Class

Represents a Windows radio button.

For a list of all members of this type, see RadioButton Members.

System.Object
   System.MarshalByRefObject
      System.ComponentModel.Component
         System.Windows.Forms.Control
            System.Windows.Forms.ButtonBase
               System.Windows.Forms.RadioButton

[Visual Basic]
Public Class RadioButton
   Inherits ButtonBase
[C#]
public class RadioButton : ButtonBase
[C++]
public __gc class RadioButton : public ButtonBase
[JScript]
public class RadioButton extends ButtonBase

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Remarks

The RadioButton control can display text, an Image, or both.

When the user selects one radio button within a group, the others clear automatically. All RadioButton controls in a given container, such as a Form, constitute a group. To create multiple groups on one form, place each group in its own container, such as a GroupBox or Panel control.

RadioButton and CheckBox controls have a similar function: they offer choices a user can select or clear. The difference is that multiple CheckBox controls can be selected at the same time, but radio buttons are mutually exclusive.

Use the Checked property to get or set the state of a RadioButton. The radio button's appearance can be altered to appear as a toggle-style button or as a standard radio button by setting the Appearance property.

Note   The radio button is sometimes referred to as an option button.

Example

[Visual Basic, C#, C++] The following example creates and initializes a RadioButton, gives it the appearance of a toggle button, sets its AutoCheck property to false, and adds it to a Form.

[Visual Basic] 
Private Sub InitializeMyRadioButton()
    ' Create and initialize a new RadioButton. 
    Dim radioButton1 As New RadioButton()
       
    ' Make the radio button control appear as a toggle button.
    radioButton1.Appearance = Appearance.Button
       
    ' Turn off the update of the display on the click of the control.
    radioButton1.AutoCheck = False
       
    ' Add the radio button to the form.
    Controls.Add(radioButton1)
End Sub


[C#] 
private void InitializeMyRadioButton()
{
   // Create and initialize a new RadioButton. 
   RadioButton radioButton1 = new RadioButton();
   
   // Make the radio button control appear as a toggle button.
   radioButton1.Appearance = Appearance.Button;

   // Turn off the update of the display on the click of the control.
   radioButton1.AutoCheck = false;

   // Add the radio button to the form.
   Controls.Add(radioButton1);
}


[C++] 
private:
    void InitializeMyRadioButton() {
        // Create and initialize a new RadioButton. 
        RadioButton __gc *radioButton1 = new RadioButton();

        // Make the radio button control appear as a toggle button.
        radioButton1->Appearance = Appearance::Button;

        // Turn off the update of the display on the click of the control.
        radioButton1->AutoCheck = false;

        // Add the radio button to the form.
        Controls->Add(radioButton1);
    };

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Namespace: System.Windows.Forms

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

Assembly: System.Windows.Forms (in System.Windows.Forms.dll)

See Also

RadioButton Members | System.Windows.Forms Namespace | ButtonBase | Button | CheckBox

Show:
© 2014 Microsoft