Freigeben über


CheckBox-Klasse

Stellt eine Windows-CheckBox dar.

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

Syntax

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

Hinweise

Mit einem CheckBox bieten Sie Benutzern Optionen zur Auswahl, beispielsweise wahr/falsch oder ja/nein. Das CheckBox-Steuerelement kann Bilder und/oder Text anzeigen.

Das CheckBox-Steuerelement und das RadioButton-Steuerelement erfüllen ähnliche Funktionen: Benutzer können Optionen aus einer Liste auswählen. Bei CheckBox-Steuerelementen ist es möglich, eine Kombination von Optionen auszuwählen. Im Gegensatz dazu können bei RadioButton-Steuerelementen vom Benutzer jeweils nur eine der sich gegenseitig ausschließenden Optionen ausgewählt werden.

Die Appearance-Eigenschaft bestimmt, ob die CheckBox als typische CheckBox oder als Schaltfläche angezeigt wird.

Die ThreeState-Eigenschaft bestimmt, ob das Steuerelement zwei oder drei Zustände unterstützt. Bei einem CheckBox-Steuerelement mit zwei Zuständen wird die Checked-Eigenschaft verwendet, um dessen Wert abzurufen oder festzulegen. Mithilfe der CheckState-Eigenschaft können Sie den Wert eines CheckBox-Steuerelements mit drei Zuständen abrufen oder festlegen.

Hinweis

Wenn die ThreeState-Eigenschaft auf true festgelegt ist, gibt die Checked-Eigenschaft für einen aktivierten oder einen unbestimmten Zustand true zurück.

Die FlatStyle-Eigenschaft bestimmt den Stil und die Darstellung des Steuerelements. Wenn die FlatStyle-Eigenschaft auf FlatStyle.System festgelegt ist, wird die Darstellung des Steuerelements durch das Betriebssystem des Benutzers bestimmt.

Hinweis

Wenn die FlatStyle-Eigenschaft auf FlatStyle.System festgelegt ist, wird die CheckAlign-Eigenschaft ignoriert und das Steuerelement mit ContentAlignment.MiddleLeft-Ausrichtung oder der ContentAlignment.MiddleRight-Ausrichtung angezeigt. Wenn die CheckAlign-Eigenschaft auf eine rechtsbündige Ausrichtung festgelegt ist, wird das Steuerelement mit ContentAlignment.MiddleRight-Ausrichtung angezeigt. Andernfalls wird es mit ContentAlignment.MiddleLeft-Ausrichtung angezeigt.

Im Folgenden wird ein unbestimmter Zustand beschrieben: Mit einer CheckBox wird bestimmt, ob der in einer RichTextBox markierte Text fett formatiert ist. Wenn Sie Text markiert haben, können Sie diesen fett formatieren, indem Sie auf die CheckBox klicken. Ebenso zeigt die CheckBox beim Markieren von Textstellen an, ob der ausgewählte Text fett formatiert ist. Wenn der markierte Text teilweise fett und teilweise normal formatiert ist, befindet sich die CheckBox im unbestimmten Zustand.

Beispiel

Im folgenden Beispiel wird eine CheckBox erstellt und initialisiert. Diese wird als Umschaltfläche dargestellt, der Wert für AutoCheck wird auf false festgelegt, und sie wird einem Form hinzugefügt.

Public Sub InstantiateMyCheckBox()
    ' Create and initialize a CheckBox.   
    Dim checkBox1 As New CheckBox()
    
    ' Make the check box control appear as a toggle button.
    checkBox1.Appearance = Appearance.Button
    
    ' Turn off the update of the display on the click of the control.
    checkBox1.AutoCheck = False
    
    ' Add the check box control to the form.
    Controls.Add(checkBox1)
End Sub 'InstantiateMyCheckBox
public void InstantiateMyCheckBox()
 {
    // Create and initialize a CheckBox.   
    CheckBox checkBox1 = new CheckBox(); 
    
    // Make the check box control appear as a toggle button.
    checkBox1.Appearance = Appearance.Button;
 
    // Turn off the update of the display on the click of the control.
    checkBox1.AutoCheck = false;
 
    // Add the check box control to the form.
    Controls.Add(checkBox1);
 }
 
public:
   void InstantiateMyCheckBox()
   {
      // Create and initialize a CheckBox.   
      CheckBox^ checkBox1 = gcnew CheckBox;
      
      // Make the check box control appear as a toggle button.
      checkBox1->Appearance = Appearance::Button;
      
      // Turn off the update of the display on the click of the control.
      checkBox1->AutoCheck = false;
      
      // Add the check box control to the form.
      this->Controls->Add( checkBox1 );
   }
public void InstantiateMyCheckBox()
{
    // Create and initialize a CheckBox.   
    CheckBox checkBox1 = new CheckBox();

    // Make the check box control appear as a toggle button.
    checkBox1.set_Appearance(Appearance.Button);

    // Turn off the update of the display on the click of the control.
    checkBox1.set_AutoCheck(false);

    // Add the check box control to the form.
    get_Controls().Add(checkBox1);
} //InstantiateMyCheckBox
public function InstantiateMyCheckBox()
 {
    // Create and initialize a CheckBox.   
    var checkBox1 : CheckBox = new CheckBox(); 
    
    // Make the check box control appear as a toggle button.
    checkBox1.Appearance = Appearance.Button;
 
    // Turn off the update of the display on the click of the control.
    checkBox1.AutoCheck = false;
 
    // Add the check box control to the form.
    Controls.Add(checkBox1);
 }
 

Vererbungshierarchie

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

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 Mobile für Smartphone, 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

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

Weitere Ressourcen

CheckBox-Steuerelement (Windows Forms)