• We just launched and are currently in beta. Join us as we build and grow the community.

CheckBox Control

qadir222

Cyber Awareness Educator
Divine
Q Rep
0
0
0
Rep
0
Q Vouches
0
0
0
Vouches
0
Posts
197
Likes
111
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 200 XP
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. If

    CheckBox1.

    Checked

    =

    True

    Then
  4. country =

    "Philippines"
  5. End

    If

  6. If

    CheckBox2.

    Checked

    =

    True

    Then
  7. country =

    country &

    " America"
  8. End

    If

  9. If

    CheckBox3.

    Checked

    =

    True

    Then
  10. country =

    country &

    " Canada"
  11. End

    If
  12. MsgBox

    (

    country &

    " is selected "

    )

  13. 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:

checkphil.png

checktwo.png

checkall.png


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: https://www.facebook.com/donzzsky

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


Download
You must upgrade your account or reply in the thread to view hidden text.
 

452,292

323,340

323,349

Top