Skip to main content

CheckBox Control


I had discussed RadioButton a while ago and now I will introduce the CheckBox Control in VB.NET. CheckBox and RadioButton controls have a similar function: they allow the user to choose from a list of options. CheckBox controls let the user pick a combination of options. In contrast, RadioButton controls allow a user to choose from mutually exclusive options. They have the same popular event of .Checked.

1. Let's start with creating a Windows Form Application for this tutorial by following the following steps in Microsoft Visual Studio: Go to File, click New Project, and choose Windows Application.

2. Next, add three CheckBoxes namely CheckBox1 labeled as "Philippines", CheckBox2 labeled as "America", and CheckBox3 labeled as "Canada". Add one Button named Button1 for choosing this country. You must design your layout like this:

3. Now, put this code in Button1_Click. This will choose the checked CheckBoxes you chose.

  1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  2. Dim country As String = ""
  3.  
  4. If CheckBox1.Checked = True Then
  5. country = "Philippines"
  6. End If
  7.  
  8. If CheckBox2.Checked = True Then
  9. country = country & " America"
  10. End If
  11.  
  12. If CheckBox3.Checked = True Then
  13. country = country & " Canada"
  14. End If
  15. MsgBox(country & " is selected ")
  16.  
  17. End Sub

Explanation:

We initialized country As String = "" to have a value regarding to our chosen CheckBoxes. If we check checkbox1, that is CheckBox1.Checked = True, the variable country holds the value of "Philippines". If we check checkbox2, that is CheckBox2.Checked = True, the variable country holds the value of "America", and lastly if we check checkbox3, that is CheckBox3.Checked = True. We used multiple ifs to create a multi selection rather than If-else so that if we have two or three checkboxes checked, the country variable now holds two or three strings that will append and appear with the use of MessageBox. Thus, it will prompt the user that you have selected that country when you checked that certain CheckBoxes.

Output:

output

output

output

Download the source code below and try it! :)

For more inquiries and need programmer for your thesis systems in any kind of programming languages, just contact my number below.

Best Regards,

Engr. Lyndon R. Bermoy
IT Instructor/System Developer/Android Developer
Mobile: 09079373999
Telephone: 826-9296
E-mail:[email protected]

Visit and like my page on Facebook at: https://www.facebook.com/BermzISware

Subscribe at my YouTube Channel at: Ser Bermz

Visit my website at: www.campcodes.com

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.

FOR YOUR OWN SAFETY, PLEASE:

1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

Add new comment

CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.