Search | Contact | Link To Us  

      VB .NET      

.NET Defined
OOP with VB
VB Language
Win Forms
Windows Controls
ADO .NET
User Controls
File Handling
Multithreading
Deployment
XML Web Services Essential XML
Resources
Discussions
ASP.NET
About



Advertisement


     Home> Windows Controls> RadioButton


RadioButton

RadioButtons are similar to CheckBoxes but RadioButtons are displayed as rounded instead of boxed as with a checkbox. Like CheckBoxes, RadioButtons are used to select and deselect options but they allow us to choose from mutually exclusive options. The RadioButton control is based on the ButtonBase class which is based on the Control class. A major difference between CheckBoxes and RadioButtons is, RadioButtons are mostly used together in a group. Below is the image of a RadioButton.

Important properties of the RadioButton in the Appearance section of the properties window are:

Appearance: Default value is Normal. Set the value to Button if you want the RadioButton to be displayed as a Button.
BackgroundImage: Used to set a background image for the RadioButton.
CheckAlign: Used to set the alignment for the RadioButton from a predefined list.
Checked: Default value is False, set it to True if you want the RadioButton to be displayed as checked.
FlatStyle: Default value is Standard. Select the value from a predefined list to set the style of the RadioButton.

RadioButton Event

The default event of the RadioButton is the CheckedChange event which looks like this in code:

Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object,_
ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged

End Sub

Working with Examples

Drag a RadioButton (RadioButton1), TextBox (TextBox1) and a Button (Button1) from the Toolbox.

Code to display some text when the RadioButton is selected

Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged
TextBox1.Text = "RadioButton Selected"
End Sub

Code to check a RadioButton's state

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As_
System.EventArgs) Handles Button1.Click
If RadioButton1.Checked = True Then
TextBox1.Text = "Selected"
Else
TextBox1.Text = "Not Selected"
End If
End Sub

Creating a RadioButton in Code

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As_
System.EventArgs) Handles_ MyBase.Load
Dim RadioButton1 As New RadioButton()
RadioButton1.Text = "RadioButton1"
RadioButton1.Location = New Point(120,60)
RadioButton1.Size = New Size(100, 50)
Me.Controls.Add(RadioButton1)
End Sub

For Properties See: Control Object Properties - Form Properties

  Privacy Policy | Terms of Use | Site Map | Contact

  © 2004-2010 Startvbdotnet.com. All rights reserved.