Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
RadioButton Class

  Switch on low bandwidth view
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
RadioButton Class

Enables the user to select a single option from a group of choices when paired with other RadioButton controls.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)
Visual Basic (Declaration)
<ComVisibleAttribute(True)> _
<ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)> _
<DefaultBindingPropertyAttribute("Checked")> _
Public Class RadioButton _
    Inherits ButtonBase
Visual Basic (Usage)
Dim instance As RadioButton
C#
[ComVisibleAttribute(true)]
[ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)]
[DefaultBindingPropertyAttribute("Checked")]
public class RadioButton : ButtonBase
Visual C++
[ComVisibleAttribute(true)]
[ClassInterfaceAttribute(ClassInterfaceType::AutoDispatch)]
[DefaultBindingPropertyAttribute(L"Checked")]
public ref class RadioButton : public ButtonBase
JScript
public class RadioButton extends ButtonBase

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

When the user selects one option button (also known as a 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 option buttons are mutually exclusive.

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

The following code example creates and initializes two RadioButton controls in a GroupBox. To run this example, paste the code into a Windows Form. Call InitializeRadioButtons from the form's constructor or the Load event-handling method.

Visual Basic
Private groupBox1 As GroupBox
Private radioButton2 As RadioButton
Private radioButton1 As RadioButton


Public Sub InitializeRadioButtons() 
    Me.groupBox1 = New System.Windows.Forms.GroupBox()
    Me.radioButton2 = New System.Windows.Forms.RadioButton()
    Me.radioButton1 = New System.Windows.Forms.RadioButton()

    Me.groupBox1.Controls.Add(Me.radioButton2)
    Me.groupBox1.Controls.Add(Me.radioButton1)
    Me.groupBox1.Location = New System.Drawing.Point(80, 75)
    Me.groupBox1.Size = New System.Drawing.Size(200, 100)
    Me.groupBox1.Text = "Radio Buttons"

    Me.radioButton2.Location = New System.Drawing.Point(31, 53)
    Me.radioButton2.Size = New System.Drawing.Size(67, 17)
    Me.radioButton2.Text = "Choice 2"

    Me.radioButton1.Location = New System.Drawing.Point(31, 20)
    Me.radioButton1.Name = "radioButton1"
    Me.radioButton1.Size = New System.Drawing.Size(67, 17)
    Me.radioButton1.Text = "Choice 1"

    Me.ClientSize = New System.Drawing.Size(292, 266)
    Me.Controls.Add(Me.groupBox1)

End Sub


C#
private GroupBox groupBox1;
private RadioButton radioButton2;
private RadioButton radioButton1;

public void InitializeRadioButtons()
{
    this.groupBox1 = new System.Windows.Forms.GroupBox();
    this.radioButton2 = new System.Windows.Forms.RadioButton();
    this.radioButton1 = new System.Windows.Forms.RadioButton();

    this.groupBox1.Controls.Add(this.radioButton2);
    this.groupBox1.Controls.Add(this.radioButton1);
    this.groupBox1.Location = new System.Drawing.Point(80, 75);
    this.groupBox1.Size = new System.Drawing.Size(200, 100);
    this.groupBox1.Text = "Radio Buttons";

    this.radioButton2.Location = new System.Drawing.Point(31, 53);
    this.radioButton2.Size = new System.Drawing.Size(67, 17);
    this.radioButton2.Text = "Choice 2";

    this.radioButton1.Location = new System.Drawing.Point(31, 20);
    this.radioButton1.Name = "radioButton1";
    this.radioButton1.Size = new System.Drawing.Size(67, 17);
    this.radioButton1.Text = "Choice 1";

    this.ClientSize = new System.Drawing.Size(292, 266);
    this.Controls.Add(this.groupBox1);
}

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

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Pocket PC

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 3.5, 2.0, 1.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker