Files
docs-desktop/dotnet-desktop-guide/framework/winforms/controls/how-to-set-options-with-windows-forms-checkbox-controls.md
T
Andy De George c0ba284473 Initial winforms content migrated (#18)
* Merge winforms framework content to working branch (#14)

* Breadcrumb / TOC / Move net5 to net folder (#15)

* change path from net5 to net

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Add .net 5 winforms placeholder article (#16)

* added some metadata and adjusted net5 placeholder

* corrections

* corrections

* corrections

* Test1

* Swapping landing page vs concept

* fix links

* Fix links

* Fix desc
2020-09-01 16:26:21 -07:00

2.6 KiB

title, ms.date, dev_langs, f1_keywords, helpviewer_keywords, ms.assetid
title ms.date dev_langs f1_keywords helpviewer_keywords ms.assetid
Set Options with CheckBox Controls 03/30/2017
csharp
vb
cpp
checked
CheckBox control [Windows Forms], checked state
check boxes [Windows Forms], using to set options
CheckBox control [Windows Forms], using to set options
2ac70498-7e3e-4e07-8901-ccabaeb5fd3e

How to: Set Options with Windows Forms CheckBox Controls

A Windows Forms xref:System.Windows.Forms.CheckBox control is used to give users True/False or Yes/No options. The control displays a check mark when it is selected.

To set options with CheckBox controls

  1. Examine the value of the xref:System.Windows.Forms.CheckBox.Checked%2A property to determine its state, and use that value to set an option.

    In the code sample below, when the xref:System.Windows.Forms.CheckBox control's xref:System.Windows.Forms.CheckBox.CheckedChanged event is raised, the form's xref:System.Windows.Forms.Control.AllowDrop%2A property is set to false if the check box is checked. This is useful for situations where you want to restrict user interaction.

    Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, _  
       ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged  
       ' Determine the CheckState of the check box.  
       If CheckBox1.CheckState = CheckState.Checked Then  
          ' If checked, do not allow items to be dragged onto the form.  
          Me.AllowDrop = False  
       End If  
    End Sub  
    
    private void checkBox1_CheckedChanged(object sender, System.EventArgs e)  
    {  
       // Determine the CheckState of the check box.  
       if (checkBox1.CheckState == CheckState.Checked)
       {  
          // If checked, do not allow items to be dragged onto the form.  
          this.AllowDrop = false;  
       }  
    }  
    
    private:  
       void checkBox1_CheckedChanged(System::Object ^ sender,  
          System::EventArgs ^ e)  
       {  
          // Determine the CheckState of the check box.  
          if (checkBox1->CheckState == CheckState::Checked)
          {  
             // If checked, do not allow items to be dragged onto the form.  
             this->AllowDrop = false;  
          }  
       }  
    

See also