ITSourceCode.com

We Exist to Provide 100% Free Source Code and Tutorials

Custom Search

09-The Radio Button And The CheckBox

This section will help you learn how to use  radiobuttons and checkboxes for presenting and retrieving user choices.

 

Radio buttons  or also known as option buttons always work as part of a group. For instance, if you select one radio button in the group it immediately clears all the other radio buttons.

 

See the example below on how to use Radio Buttons

  1. From the Toolbox, drag two Radio Buttons controls and a Button into the form.
  2. In the Properties window, change the Text property of the RadioButton1 to “Male”  and set the check property to true.
    Take Note that when defining group of choices, always set one choice to be the default.
  3. In the Properties window, change the Text property of the RadioButton1 to “Female” 
  4. In the form, double-click the button to fire the Button1_Click event handler in the Code Editor.
  5. In the Button1_Click event handler, add the following code:
  1. <pre>If RadioButton1.Checked = True Then
  2.     MsgBox("The gender that you select is Male")
  3. Else
  4.     MsgBox("The gender that you select is Female")
  5. End If</pre>

Press f5 to run your project.

Output:

rdo1

 

CheckBox control consists of a text label and a box  in which the user can select. A check mark appears in the box when the user clicks the box.

 

See the example below on how to use a checkbox:

 

  1. From the Toolbox, drag a Button and three CheckBox controls onto the form.
  2. In the Properties Window, change the Text property of CheckBox1 to “Male” and CheckBox2 to “Female”.
  3. In the Properties window, change the Text property of Button1 to read Submit.
  4. In the form, double-click the button; this fire the Button1_Click event handler in the Code Editor.
  5. Add the following code to the Button1_Click event handler:
  1. <pre> Dim gender As String = ""
  2.  If CheckBox1.Checked = True Then
  3.  gender &amp;= "Male"
  4.  End If
  5.  If CheckBox2.Checked = True Then
  6.  gender &amp;= "Female "
  7.  End If
  8.  
  9.  If gender &lt;&gt; "" Then
  10.  MsgBox("The gender that you select is " &amp; gender)
  11.  End If</pre>

output:

chck2

 

 

Facebook Comments

Check Your Domain Ranking

Leave a Reply

Your email address will not be published. Required fields are marked *

ITSourceCode.com © 2016 Frontier Theme

Subscribe For Latest Updates

Signup for our newsletter and get notified when we publish new articles for free!