The CheckBox control is part of Windows form. It is a graphical user interface (GUI) control that is either checked or unchecked and used to select single or multiple elements from the given list or it can provide us options like yes or no, true or false, etc. It can be displayed as an image text or both. The CheckBox is a class and is defined under System.Windows.Forms namespace.
Ways to Create a Checkbox In Windows Forms
There are mainly two ways to create a checkbox in Windows forms which are mentioned below.
- Drag and drop (Design-Time)
- Custom CheckBox (Run-Time)
Drag and drop (Design-Time)
This is the easiest way to create a CheckBox in Windows Forms using Visual Studio we just have to open the toolbox and drag and drop the CheckBox on the form in the designer and further we can change the appearance of the CheckBox using the properties. Follow these steps to create a CheckBox.
Step 1: Now locate the project with the name here we are using the default name which is Form1 and it will open a form in the editor which we can further modify.

In the image, we have two files that are open one Design and there is Form1.cs these two play a major role. We use the Form 1.cs file for the custom logic.
Step 2: Now open a Toolbox go to the view > Toolbox or ctrl + alt + x.

Step 3. Now open the common controls and drag and drop the CheckBox on the form where we want it to be placed.

Step 4. Now open the properties of the Checkbox press right-click on the CheckBox and it will open the properties solution explorer now we can change the text content of the checkbox
Now we can add different checkboxes and change their appearance and behaviour in the properties these are the changes we created with a label text to make a checkbox.
Output:

In the output image, we can see that here we can choose multiple options from the given options unlike a RadioButton where we can choose only one option from the given ones.
Custom CheckBox (Run-Time)
In this method, we are going to modify the Form1.cs file and add custom code modifications in C# to change the appearance of the CheckBox according to our requirements. Follow these step-by-step processes.
Step 1: Create a checkbox using the CheckBox() constructor provided by the CheckBox class.
// Creating checkbox
CheckBox Mycheckbox = new CheckBox();
Step 2: After creating CheckBox, set the properties of the CheckBox provided by the CheckBox class.
// Set height of the checkbox
Mycheckbox.Height = 50;
// Set width of the checkbox
Mycheckbox.Width = 100;
// Set location of the checkbox
Mycheckbox.Location = new Point(229, 136);
// Set text in the checkbox
Mycheckbox.Text = “Married”;
// Set font of the checkbox
Mycheckbox.Font = new Font(“Bradley Hand ITC”, 12);
Step 3: And last add this checkbox control to form using Add() method.
// Add this checkbox to form
this.Controls.Add(Mycheckbox);
Step 4: Now double-click on the button in Design and it will open the Form cs file where code is written in C#. Here the program file is Form 1.cs Now write this code in Form1.cs file
Form1.cs file:
C#
namespace WinFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
Label l = new Label();
l.Text = "Choose the languages you speak";
l.AutoSize = true;
l.Location = new Point(180, 111);
l.Font = new Font("Bradley Hand ITC", 12);
// Adding label to form
this.Controls.Add(l);
// Creating and setting the properties of CheckBox
CheckBox Mycheckbox = new CheckBox();
Mycheckbox.Height = 50;
Mycheckbox.Width = 100;
Mycheckbox.Location = new Point(229, 136);
Mycheckbox.Text = "English";
Mycheckbox.Font = new Font("Bradley Hand ITC", 12);
// Adding checkbox to form
this.Controls.Add(Mycheckbox);
// Creating and setting the properties of CheckBox
CheckBox Mycheckbox1 = new CheckBox();
Mycheckbox1.Location = new Point(230, 198);
Mycheckbox1.Text = "Hindi";
Mycheckbox1.AutoSize = true;
Mycheckbox1.Font = new Font("Bradley Hand ITC", 12);
// Adding checkbox to form
this.Controls.Add(Mycheckbox1);
}
}
}
Output:

Properties of CheckBox
Property | Description |
---|
Appearance | This property is used to get or set the value that indicates the appearance of a CheckBox control. |
AutoCheck | This property is used to set a value which shows whether the Checked or CheckState values and the CheckBox appearance are automatically changed when you click the CheckBox. |
AutoEllipsis | This property is used to get or set a value which determines whether the ellipsis character (…) appears at the right edge of the control, denoting that the control text extends beyond the specified length of the control. |
AutoSize | This property is used to get or set a value that determines whether the control resizes based on its contents. |
BackColor | This property is used to get or set the background colour of the control. |
BackgroundImage | This property is used to get or set the background image displayed in the control. |
CheckState | This property is used to get or set the state of the CheckBox. |
CheckAlign | This property is used to get or set the horizontal and vertical alignment of the check mark on a CheckBox control. |
Checked | This property is used to get or set a value which determines whether the CheckBox is in the checked state. |
Events | This property is used to get the list of event handlers that are attached to this Component. |
Font | This property is used to get or set the font of the text displayed by the control. |
ForeColor | This property is used to get or set the foreground color of the control. |
Image | This property is used to get or set the image that is displayed on a checkbox control. |
Location | This property is used to get or set the coordinates of the upper-left corner of the CheckBox control relative to the upper-left corner of its form. |
Margin | This property is used to get or set the space between controls. |
Name | This property is used to get or set the name of the control. |
Padding | This property is used to get or set padding within the control. |
Text | This property is used to get or set the text associated with this control. |
TextAlign | This property is used to get or set the alignment of the text on the CheckBox control. |
Visible | This property is used to get or set a value which determines whether the control and all its child controls are displayed. |
Events On CheckBox
Event | Description |
---|
CheckedChanged | This event occurs when the value of the Checked property changes. |
CheckStateChanged | This event occurs when the value of the CheckState property changes. |
Click | This event occurs when the control is clicked. |
DoubleClick | This event occurs when the user double-clicks the CheckBox control. |
Leave | This event occurs when the input focus leaves the control. |
MouseClick | This event occurs when the control is clicked by the mouse. |
MouseDoubleClick | This event occurs when the user double-clicks the CheckBox control. |
MouseHover | This event occurs when the mouse pointer rests on the control. |
Similar Reads
C# | Uri.CheckHostName(String) Method
Uri.CheckHostName(String) Method is used to determine whether the specified host name is a valid DNS name or not. Syntax: public static UriHostNameType CheckHostName (string name); Here, it takes the host name to validate. This can be an IPv4 or IPv6 address or an Internet host name. Return Value: T
2 min read
C# | Uri.CheckSchemeName(String) Method
Uri.CheckSchemeName(String) Method is used to determine whether the specified scheme name is valid or not. Syntax: public static bool CheckSchemeName (string schemeName); Here, it takes the scheme name to validate. Return Value: This method returns a Boolean value true if the scheme name is valid ot
2 min read
C# | String Operators
The string is an array of characters. The String class represents the text as a series of Unicode characters and it is defined in the .NET base class library. The main use of the String class is to provide the properties, operators and methods so that it becomes easy to work with strings.There are t
4 min read
How to use AutoCheck property of CheckBox in C#?
The CheckBox control is the part of the windows form that is used to take input from the user. Or in other words, CheckBox control allows us to select single or multiple elements from the given list. You are allowed to set a value that determines the Checked or CheckedStates values and also the appe
3 min read
C# | String.Contains() Method
In C#, the String.Contains() method is used to check whether a substring exists within a given string. It returns a Boolean value (true or false) indicating whether the substring is found. By default, the method performs a case-sensitive comparison. Example 1: Here, we are using the String.Contains(
3 min read
C# UInt32 Struct
In C#, the UInt32 struct represents a 32-bit unsigned integer (commonly referred to as the uint data type). It is defined in the System namespace and provides various methods for mathematical computations, parsing, and type conversion. Because of it is an unsigned type, it only holds non-negative va
2 min read
C# | Check if the BitArray is read-only
The BitArray class manages a compact array of bit values, which are represented as Booleans, where true indicates that the bit is on i.e, 1 and false indicates the bit is off i.e, 0. This class is contained in System.Collections namespace. BitArray.IsReadOnly property is used to get a value indicati
2 min read
C# | Uri.IsHexEncoding() Method
Uri.IsHexEncoding(String, Int32) Method is used to check whether a character in a string is hexadecimal encoded or not. This checks for hexadecimal encoding which follows the pattern "%hexhex" in a string, where "hex" is a digit from 0 to 9 or a letter from A-F (case-insensitive). Syntax: public sta
2 min read
C# | Check if a SortedList is read-only
SortedList class is a collection of (key, value) pairs which are sorted according to keys. Those pairs can be accessible by key and as well as by index(zero-based indexing). This comes under System.Collections namespace. SortedList.IsReadOnly property is used to get a value which indicates that a So
2 min read
C# | Char.IsNumber() Method
In C#, Char.IsNumber() is a System.Char struct method which is used to check whether a Unicode character can be categorized as a number or not. Valid numbers will be the members of the UnicodeCategory.DecimalDigitNumber, UnicodeCategory.LetterNumber, or UnicodeCategory.OtherNumber category. This met
3 min read