Checkbox Control in C#

In this article, we will learn how to use the checkbox and checked list box in windows form in C#.

Let's create a windows form.

Step 1
In Visual Studio select "File" = > "New" = > "Project..." then select C# Windows Forms Application then click Ok.

create windows form

Step 2
Let's create a checkbox then you go "View" = > select "ToolBox" (Crtl+Alt+X) = > then select "All Windows Forms" = > Choose "checkbox".

  1. First of all, we'll know about the "CheckBox".

    checkbox enables the user to select or clear the associated options in c#. We'll discuss properties and functions and events of checkbox write down.

    "AutoCheck" causes the checkbox to automatically change state when clicked.

    checkBox1.AutoCheck = false;

    "AutoEllipsis" Enables the automatic handling of text that extends beyond the width of the button.

    checkBox1.AutoEllipsis = true;

    "AutoSize" Specifies whether a control will automatically size itself to fit its contents.

    checkBox1.AutoSize = true;

    "BackColor" changes the the background color of checkbox.

    checkBox1.BackColor = Color.Red;

    "BackgroundImage" gets or sets background display image of checkbox.

    checkBox1.BackgroundImage=_your image;

    "BackgroundImageLayout" gets or sets background image layout to show the background image of checkbox.

    checkBox1.BackgroundImageLayout = ImageLayout.Tile;

    "CheckAlign" Determines the location of the check box inside the control.

    checkBox1.CheckAlign = ContentAlignment.MiddleRight;

    "Checked" Indicates whether the component is in the checked state.

    if (checkBox1.Checked)
        //Your code here
        //Your code here

    "CheckState" Indicates the state of the component. It has three options there are : Unchecked,Checked,Indeterminate.

    checkBox1.CheckState = CheckState.Checked;

    "Cursor" The cursor that appears when the pointer moves over the control.

    checkBox1.Cursor = Cursors.Hand;

    "Dock" gets or sets which control borders are docked to its parent control and determines how a control is resized with its parent.

    checkBox1.Dock = DockStyle.Fill;

    "Enabled" gets or sets a value indicating whether the control can respond to use interaction.

    checkBox1.Enabled = false;

    "FlatStyle" gets or sets the flat style appearance of the button control.

    checkBox1.FlatStyle = FlatStyle.Popup;

    "Font" gets or sets the font of the text displayed by the control.

    checkBox1.Font = new Font("cursive", 12.0F, FontStyle.Bold);

    "ForeColor" gets or sets the font color of checkbox.

    checkBox1.ForeColor = Color.Blue;

    "Hide()" hides the checkbox to the user.


    "Reset()" resets the text values of the checkbox to its default values.


    "Show()" displays the checkbox to the user.


    "Text" text of the checkbox.


    "Visible" defines the checkbox are display or not.


Write a comment

Name Email Message