Radio Button Control in VB.net – Properties, Methods and Events

What is Radio Button in Control in VB.net?

The Radio Button Control in VB.net is used to choose one choice from the available options. In windows forms, we may utilize the radio button to pick just one thing from a related or set of items. The Radio Buttons in VB.net is mutually exclusive, signifying that only one item is selected and active in the form.

See also all the Basic Control Using VB.net with Source Code….

In order for you to test your VB.net Code provided in this lesson, you must test the code in your code editor. But if you wish to run this code online, we also have an Online Compiler in VB.net for you to test your VB.net Code for free.

We have learned how to use the ListBox Control in VB.net in the previous lesson. In this lesson we shall learn How To Write a Program for Radio Button Control in VB.net.

Let’s create Radio Buttons in VB.net by dragging Radio Button controls from the Toolbox and dropping on the form.

Radio Button Control in VB.net Tutorial
Radio Button Control Tutorial

The state of a radio button is set using the Checked Property of the radio button. On a radio button control, text, an image, or both can be shown. Using the Appearance Property, you can also alter how the radio button control looks.

Properties of Radio Button Control in VB.net

The following given below are some commonly used Properties of the Radio Button Control in VB.net.

#Properties of Radio Button Control in VB.netDescription
1.AllowDropIt is used to set or get a value representing whether the RadioButton allows the user to drag on the form.
2.AppearanceIt is used to get or set a value that represents the appearance of the RadioButton.
3.AutoScrollOffsetIt is used to get or set the radio control in ScrollControlIntoView(Control).
4.AutoCheckThe AutoCheck property is used to check whether the checked value or appearance of control can be automatically changed when the user clicked on the RadioButton control.
5.AutoSizeThe AutoSize property is used to check whether the radio control can be automatically resized by setting a value in the RadioButton control.
6.CanSelectA CanSelect property is used to validate whether a radio control can be selected by setting a value in the RadioButton control.
7.CheckAlignIt is used to obtain or set a value that indicates the location of the check portion in the radioButton control.
8.TextThe Text property is used to set the name of the RadioButton control.
Properties and Descriptions of Radio Button Control in VB.net

Methods of Radio Button Control in VB.net

The following given below are some commonly used Methods of the Radio Button Control in VB.net.

#Methods of Radio Button Control in VB.netDescription
1.Contains(Control)The Contains() method is used to check if the defined control is available in the RadioButton control.
2.DefWndProc(Message)It is used to send the specified message to the Window procedure.
3.DestroHandle()It is used to destroy the handle associated with the RadioButton Control.
4.Focus()The Focus() method is used to set the input focus to the window form’s RadioButton control.
5.GetAutoSizeMode()It is used to return a value that represents how the control will operate when the AutoSize property is enabled in the RadioButton control of the Window form.
6.ResetText()As the name suggests, a ResetText() method is used to reset the property of text to its default value or empty.
7.Update()It is used to reroute an invalid field, which causes control in the client region.
Methods and Descriptions of Radio Button Control

Events of Radio Button Control in VB.net

The following given below are some commonly used Events of the Radio Button Control in VB.net.

#Events of Radio Button Control in VB.netDescription
1AppearanceChangedOccurs when the value of the Appearance property of the RadioButton control is changed.
2CheckedChangedOccurs when the value of the Checked property of the RadioButton control is changed.
Events and Descriptions of Radio Button Control

Let’s create a program to demonstrate How Radio Button Controls in VB.net Forms are used.

Public Class Form1
    Private Sub Button1_Click_4(sender As Object, e As EventArgs) Handles Button1.Click
        Dim prog As String
        If RadioButton1.Checked = True Then
            prog = "VB.NET"
            MsgBox(" Your Programming Language is : " & prog)

        ElseIf RadioButton2.Checked = True Then
            prog = "Python"
            MsgBox(" Your Programming Language is : " & prog)
        ElseIf RadioButton3.Checked = True Then
            prog = "Java"
            MsgBox(" Your Programming Language is : " & prog)
        Else
            prog = "PHP"
            MsgBox(" Your Programming Language is : " & prog)
        End If
    End Sub
End Class

Program Output:

Radio Button Control in VB.net Output
Radio Button Control Output

Click the Submit Button will show you a message like the screenshot below.

Radio Button Control in VB.net Display Message Box
Radio Button Control Display Message Box

Difference Between RadioButton Control and CheckBox Control in VB.net

Elements for making selections include checkboxes and radio buttons. While radio buttons allow the user to select exactly one thing from a list of numerous predetermined alternatives, checkboxes allow the user to select items from a fixed number of alternatives.

VB.net RadioButton Control

  • Radio buttons are used to choose one option at a time from a limited number of options.
  • Arrange radio buttons in groups (you define graphical groups in the Screen Painter). Put at least two radio buttons in one group.
  • One radio button in a group must always be selected.
  • If the user should have the chance to choose no item from the offered options, create a separate radio button with a “No selection” label or similar text that turns off the other contents-related options.

VB.net CheckBox Control

  • Checkboxes are used to choose as many options as desired at a time from a limited number of options.
  • You can select none, one, or as many options as desired in a group of checkboxes.
  • There may also be only one checkbox.
  • Choose a name that explicitly distinguishes two different states or contrasts.

Summary

In this article we have discussed on how to create a program for Radio Button Control in VB.net using Microsoft Visual Studio, we have learned how to use and manage the different Properties, Methods and Events of the Radio Button in VB.net.


Leave a Comment