Freigeben über


RadioButton-Klasse

Ermöglicht Benutzern bei Verwendung weiterer RadioButton-Steuerelemente die Auswahl einer Option aus mehreren Auswahlmöglichkeiten.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

Syntax

'Declaration
<ComVisibleAttribute(True)> _
<ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)> _
Public Class RadioButton
    Inherits ButtonBase
'Usage
Dim instance As RadioButton
[ComVisibleAttribute(true)] 
[ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)] 
public class RadioButton : ButtonBase
[ComVisibleAttribute(true)] 
[ClassInterfaceAttribute(ClassInterfaceType::AutoDispatch)] 
public ref class RadioButton : public ButtonBase
/** @attribute ComVisibleAttribute(true) */ 
/** @attribute ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) */ 
public class RadioButton extends ButtonBase
ComVisibleAttribute(true) 
ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) 
public class RadioButton extends ButtonBase

Hinweise

Im RadioButton-Steuerelement kann Text, ein Image oder beides angezeigt werden.

Wenn ein Benutzer ein Optionsfeld innerhalb einer Gruppe aktiviert, werden die anderen Optionsfelder automatisch deaktiviert. Alle RadioButton-Steuerelemente in einem bestimmten Container, z. B. Form, bilden eine Gruppe. Um mehrere Gruppen in einem Formular zu erstellen, platzieren Sie jede Gruppe in einem eigenen Container, z. B. in einem GroupBox-Steuerelement oder einem Panel-Steuerelement.

RadioButton-Steuerelemente und CheckBox-Steuerelemente haben eine ähnliche Funktion. Beide stellen Auswahlmöglichkeiten bereit, die von Benutzern aktiviert oder deaktiviert werden können. Der Unterschied besteht darin, dass mehrere CheckBox-Steuerelemente gleichzeitig aktiviert werden können, während sich Optionsfelder gegenseitig ausschließen.

Mit der Checked-Eigenschaft können Sie den Zustand eines RadioButton abrufen oder festlegen. Optionsfelder können als An-Aus-Schaltflächen oder als Standardoptionsfelder dargestellt werden, indem die Appearance-Eigenschaft festgelegt wird.

Beispiel

Im folgenden Codebeispiel wird ein RadioButton erstellt und initialisiert. Dieser soll als An-Aus-Schaltfläche dargestellt werden, die AutoCheck-Eigenschaft wird auf false festgelegt, und die Schaltfläche wird in einem Form hinzugefügt.

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
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);
}
private void InitializeMyRadioButton()
{
    // Create and initialize a new RadioButton. 
    RadioButton radioButton1 = new RadioButton();

    // Make the radio button control appear as a toggle button.
    radioButton1.set_Appearance(Appearance.Button);

    // Turn off the update of the display on the click of the control.
    radioButton1.set_AutoCheck(false);
    
    // Add the radio button to the form.
    get_Controls().Add(radioButton1);
} //InitializeMyRadioButton

Vererbungshierarchie

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

Threadsicherheit

Alle öffentlichen statischen (Shared in Visual Basic) Member dieses Typs sind threadsicher. Bei Instanzmembern ist die Threadsicherheit nicht gewährleistet.

Plattformen

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

.NET Compact Framework

Unterstützt in: 2.0, 1.0

Siehe auch

Referenz

RadioButton-Member
System.Windows.Forms-Namespace
ButtonBase-Klasse
Button-Klasse
CheckBox-Klasse