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 = ""
  4. If CheckBox1.Checked = True Then
  5. country = "Philippines"
  6. End If
  8. If CheckBox2.Checked = True Then
  9. country = country & " America"
  10. End If
  12. If CheckBox3.Checked = True Then
  13. country = country & " Canada"
  14. End If
  15. MsgBox(country & " is selected ")
  17. End Sub


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.


outputoutputoutput 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 STI College - Surigao City Mobile: 09488225971 E-mail:[email protected] Follow and add me in my Facebook Account: Visit and like my page on Facebook at:

Add new comment