Do you think IIT Guwahati certified course can help you in your career?
No
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.
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:
Using Form Designer at design time.
Using CheckBox class in code at run time.
Design Time
Steps to create a checkbox are-
Create a windows form: Visual Studio -> File -> New -> Project -> WindowsFormApp
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.
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.
Create a checkbox using the CheckBox() constructor provided by the CheckBox class. CheckBox Mycheckbox = new CheckBox();
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
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#.