Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com
Table of contents
1.
Introduction
2.
C# CheckBox Control
3.
Design Time
4.
Run Time
5.
Important Properties of CheckBox 
6.
Important Events on CheckBox
7.
FAQs
7.1.
Is C# different from C++?
7.2.
What is C# used for?
7.3.
Why is C# so popular?
7.4.
Which is faster C++ or C#?
7.5.
Is C# or C++ better for games?
8.
Conclusion
Last Updated: Mar 27, 2024
Easy

C# CheckBox Control

Author Komal Shaw
0 upvote
Master Python: Predicting weather forecasts
Speaker
Ashwin Goyal
Product Manager @

Introduction

The CheckBox control allows us to select one or more things from a list and provide options such as yes or no, true or false, and so on. It can be shown as a picture, text, or both. The CheckBox is a class that is found in the System. Windows. Forms namespace.

Recommended Topic, Palindrome in C#, singleton design pattern in c# and Ienumerable vs Iqueryable

C# CheckBox Control

CheckBoxes allow the user to make numerous choices from a list of possibilities. Give the user a choice, such as true/false or yes/no, with a checkbox. A check box can be selected by clicking it once and then deselected by clicking it again.

We can create a checkbox in two different ways:

  1. Using Form Designer at design time.
  2. Using CheckBox class in code at run time.
Get the tech career you deserve, faster!
Connect with our expert counsellors to understand how to hack your way to success
User rating 4.7/5
1:1 doubt support
95% placement record
Akash Pal
Senior Software Engineer
326% Hike After Job Bootcamp
Himanshu Gusain
Programmer Analyst
32 LPA After Job Bootcamp
After Job
Bootcamp

Design Time

Steps to create a checkbox are-

  1. Create a windows form:
    Visual Studio -> File -> New -> Project -> WindowsFormApp 
     
  2. Drag and drop the CheckBox control from the ToolBox onto the Windows form. CheckBoxes can be placed wherever on the Windows form to suit your needs.
  3. After dragging and dropping, navigate to the CheckBox control's properties to change the CheckBox design to your liking.

Run Time

It's a little more difficult than the previous way. Using the CheckBox class, you can create your own checkbox programmatically in this method.

  1. Create a checkbox using the CheckBox() constructor provided by the CheckBox class.
    CheckBox Mycheckbox = new CheckBox();
     
  2. After creating CheckBox, set the properties of the CheckBox provided by the CheckBox class. 
    Mycheckbox.Height = 40; // Set height of the checkbox
    Mycheckbox.Width = 80; // Set width of the checkbox
    Mycheckbox.Location = new Point(229, 136); // Set location of the checkbox
    Mycheckbox.Text = "Married"; // Set text in the checkbox
    Mycheckbox.Font = new Font("Bradley Hand ITC", 12); // Set font of the checkbox
     
  3. And last, add this checkbox control to the form using Add() method. 
    this.Controls.Add(Mycheckbox);

Important Properties of CheckBox 

 

Appearance

This property is used to get or set the value that indicates the appearance of a CheckBox control.

AutoCheck

When you click the CheckBox, this property is used to set a value that indicates whether the Checked or CheckState values, as well as the CheckBox look, are immediately modified.

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 color of the control.

BackgroundImage

This property is used to get or set the background image displayed in the control.

CheckAlign

This property is used to get or set the horizontal and vertical alignment of the checkmark on a CheckBox control.

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.

Image

This property is used to get or set the image that is displayed on a checkbox control.

Location

This property is used to acquire or set the coordinates of the CheckBox control's upper-left corner in relation to the form's upper-left corner.

TextAlign

This property is used to get or set the alignment of the text on the CheckBox control. 

Visible

This property gets or sets a value that determines whether the control and all of its child controls are displayed.

 

Important Events on CheckBox

 

CheckedChanged

This event occurs when the value of the Checked property changes.

CheckStateChanged

This event occur 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 occur when the control is clicked by the mouse.

 

FAQs

Is C# different from C++?

C++ is an intermediate-level language that extends C with object-oriented capabilities, whereas C# is a high-level language. C++ compiles programs to Machine Codes, whereas C# compiles programs to CLR or Common Language Runtime.

What is C# used for?

C# may be used to construct a variety of programs and applications, including mobile apps, desktop apps, cloud-based services, websites, enterprise software, and games, just like other general-purpose programming languages.

Why is C# so popular?

C# has the advantage of being able to construct applications for both mobile and computer devices. It is also extensively used by the open-source community to create software applications utilizing various frameworks like Mono and the.NET Framework.

Which is faster C++ or C#?

C++ code is substantially faster than C# code, making it a superior choice for applications that require high speed. Your network analysis software, for example, may require C++ code, but performance is unlikely to be an issue for a conventional word processing application written in C#.

Is C# or C++ better for games?

C# and C++ can both be used to make games. C++, on the other hand, has better hardware control on the PC or server. As a result, it's usually a better choice for game creation. Both languages, on the other hand, are for game creation, especially since you won't be making games from scratch (usually).

Conclusion

In this article, we have extensively discussed the C# CheckBox Control. We hope that this blog has helped you enhance your knowledge regarding the C# CheckBox Control and if you would like to learn more, check out our articles on Basics of C#Methods in C#, and Type Conversion in C#.

Refer to our guided paths on Coding Ninjas Studio to learn more about DSA, Competitive Programming, JavaScript, System Design, etc. 

Enrol in our courses and refer to the mock test and problems available.

Take a look at the interview experiences and interview bundle for placement preparations.

 

Do upvote our blog to help other ninjas grow. 

Happy Coding!

Previous article
C# RadioButton Control
Next article
C# TextBox Control
Live masterclass