The CheckBox Control
Use Windows Forms checkboxes to capture independent choices, respond to changes, and handle an indeterminate state in Visual Basic 2026.
Checked for a two-state choice and handle CheckedChanged to update the form when that Boolean value changes. For a three-state choice, use CheckState and CheckStateChanged.
21.1 Adding a CheckBox in the Designer
Create a Visual Basic Windows Forms App in Visual Studio 2026. Open Form1 in the Designer, drag a CheckBox onto the form, and set its (Name) to chkEmail and its Text to Receive email updates. Add a Label named lblStatus and set its initial text to Email updates are off. Leave Checked set to False.
21.2 CheckBox Properties and Events
TextandAutoSize- Set the caption and let the control size itself to fit that caption.
CheckedandCheckedChanged- Read the Boolean value and respond whenever it changes, including when code sets it.
CheckStateandCheckStateChanged- Read and respond to changes among
Unchecked,Checked, andIndeterminate. ThreeState- Set this to
Trueto let the user cycle through all three states.
21.3 Responding to CheckedChanged
Add this method inside Public Class Form1 in Form1.vb. Run the app and toggle the checkbox. With the checkbox focused, the Space key also toggles it.
Private Sub EmailOptionChanged(sender As Object, e As EventArgs) Handles chkEmail.CheckedChanged lblStatus.Text = If(chkEmail.Checked, "Email updates are on.", "Email updates are off.") End Sub
Email updates are off.
21.4 Grouping Independent Options
A GroupBox gives related controls a shared heading. For a lunch order, customers can select cheese, salad, both, or neither. Place one CheckBox per extra inside the GroupBox. Each option keeps its own value. Lesson 22 uses RadioButton controls for choices such as selecting a single drink size.
21.5 Working with Three States
In a separate form, add a CheckBox called chkReview, set its Text to Review status, and set ThreeState to True. Add a Label called lblReview with the initial text Review declined. Here the third state means a decision is pending. The Boolean Checked is True for both Checked and Indeterminate, so use CheckState to distinguish them.
Private Sub ReviewStateChanged(sender As Object, e As EventArgs) Handles chkReview.CheckStateChanged Select Case chkReview.CheckState Case CheckState.Unchecked lblReview.Text = "Review declined." Case CheckState.Checked lblReview.Text = "Review approved." Case CheckState.Indeterminate lblReview.Text = "Review pending." End Select End Sub
Checked = False. Review declined.
21.6 Practical Project: Lunch Order
Create a fresh Visual Basic Windows Forms App. Add a GroupBox with Text set to Lunch extras, then add the controls below. Leave both boxes unchecked. Paste the full class into Form1.vb. This project uses the F2 format specifier from Lesson 20 to show two decimal places.
- CheckBox
chkCheese, with text Cheese (RM 2.00) - CheckBox
chkSalad, with text Salad (RM 4.50) - Label
lblTotal, withAutoSizeset toTrue
Public Class Form1 Private Const BasePrice As Decimal = 12D Private Const CheesePrice As Decimal = 2D Private Const SaladPrice As Decimal = 4.5D Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load UpdateTotal() End Sub Private Sub ExtrasChanged(sender As Object, e As EventArgs) Handles chkCheese.CheckedChanged, chkSalad.CheckedChanged UpdateTotal() End Sub Private Sub UpdateTotal() Dim total As Decimal = BasePrice If chkCheese.Checked Then total += CheesePrice If chkSalad.Checked Then total += SaladPrice lblTotal.Text = $"Total: RM {total:F2}" End Sub End Class
Base lunch — RM 12.00
Total: RM 12.00
21.7 Testing the Form
Run the app and test all four combinations. With neither extra selected, expect RM 12.00. Cheese alone gives RM 14.00, salad alone gives RM 16.50, and both give RM 18.50. Clear both boxes and check that the total returns to RM 12.00. If the total fails to update, check the control names and confirm the shared event handler lists both controls after Handles.
21.8 GitHub Copilot — Extending the Lunch Order
Add btnReset in the Designer before using the suggested code. Test Reset when both extras are selected and again when both are already clear.
Lesson Summary
- Use
Checkedto read an independent on/off option. - Use
CheckedChangedto update a form when a Boolean selection changes. - Use
ThreeState,CheckState, andCheckStateChangedto distinguish an indeterminate choice. - Share an event handler when several options update the same result.
Exercises
Exercise 21.1 — Preferences
Add a second checkbox for SMS updates. Show whether email, SMS, both, or neither is selected.
Exercise 21.2 — Extra Side Dish
Add a soup option priced at RM 3.50. Update the shared handler and confirm that selecting all three extras gives RM 22.00.
Exercise 21.3 — Pending Review
Add a button that sets chkReview.CheckState to CheckState.Indeterminate. Confirm that the label updates when the state changes.
Related Resources
← Lesson 20
Format numbers, dates, and strings.
Lesson 22 →
Radio Button Control.
Microsoft Learn — CheckBox Overview
Properties and common uses of Windows Forms checkboxes.
Microsoft Learn — Setting Options
Respond to changes in a CheckBox control.
Featured Books
Visual Basic 2026 Made Easy — Second Edition
Learn VB.NET with Visual Studio 2026 and .NET 10: Windows Forms, Databases, LINQ, Async Programming, Practical Projects, and GitHub Source Code
View on Amazon → Kindle Edition →
Visual Basic 2026 Made Easy
48 fully-explained code examples spanning VB6 through VB.NET — ideal for building real-world applications.
View on Amazon → Kindle Edition →
Advanced Visual Basic 2026 Programming, Volume 1
Professional VB.NET Engineering, Object Modelling, Generics, Events, Design Patterns, and LINQ
View on Amazon → Kindle Edition →