Visual Studio 2010 CheckBox control in VB.NET
In this article, we will learn how to use a CheckBox control in a windows forms application using Visual Studio 2010.
In this article, we will learn how to use a CheckBox control in a Windows Forms application using Visual Studio 2010.
CheckBox control enables the user to select and deselect the associated option. When a checkbox is selected a check (a tick mark) appears indicating a selection. Below is the image of CheckBox:
These are some important properties of the CheckBox control:
Appearance - Property used to set or get the appearance of a checkbox.
AutoCheck - Property used to specify whether to change appearance automatically when the checkbox is clicked.
Checked - Property is used to set or get the value indicating if the checkbox is in checked state.
CheckState - Property is used to set or get state of a three state checkbox.
FlatStyle - Property set or get flatstyle appearance of the checkbox.
Image - Property is used to get or set the image displayed in checkbox.
ImageList - Property used to set or get the image list that contains the image displayed in a checkbox.
ThreeState - Property is used to specify if the checkbox will allow three check states rather than two.
The default event of the CheckBox is the CheckedChange event which looks like this in code:
Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
Creating CheckBox in code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim CheckBox1 As New CheckBox()
CheckBox1.Text = "Checkbox1"
CheckBox1.Location = New Point(100, 50)
CheckBox1.Size = New Size(95, 45)
' check box will be create.
In the above code controls is a class.
Working with CheckBox:
Drag a CheckBox ,TextBox and a Button from the Toolbox. Form looks like this.
Now double click on the button and write this code.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If CheckBox1.Checked = True Then
TextBox1.Text = "Checked"
TextBox1.Text = "UnChecked"
Now run the application and select checkbox and click on button.
Hope the article would have helped you in understanding CheckBox control in VB.NET.