How to Enable & Disable a Textbox With a Radio Button in Visual Basic

Save

Radio buttons are the small circular buttons in a user interface that allow only one of many options to be checked. Often, when Radio buttons are used, the rest of the user interface needs to respond to that selection by enabling or disabling other controls that only make sense when certain options are selected. Radio buttons can be set to enable and disable certain controls in this fashion, but it will take a little work and a little code editing.

  • Open Visual Basic and create a new project by clicking "File," then "New Project." Select "Windows Forms Project."

  • Find the "GroupBox" option in the "Toolbox" pane and drag it into your form. Radio buttons must be grouped within a "GroupBox" to function.

  • Find the "RadioButton" option in the "Toolbox" pane and drag it into your GroupBox. Right-click it, select "Properties" and set the "Text" property to read "On." Change its "Name" property to "OnButton."

  • Repeat step 3 for another "RadioButton," but this time set its "Text" property to "Off" and its "Name" property to "OffButton."

  • Find the "TextBox" in the "Toolbox" and drag it into your form. You may place it inside the GroupBox or outside it, depending on what you find best suits the design of the application.

  • Double-click the "Off" radio button to open its code editor. Paste the following:

        If OffButton.Checked Then

    TextBox1.Enabled = False

    End If

  • Click the "Design" tab and double-click the "On" button to open its code editor. Paste the following:

        If OnButton.Checked Then

    TextBox1.Enabled = True

    End If

  • Click the "Run" button. Whenever the "On" button is selected, the TextBox is enabled. Whenever the "Off" button is selected, the TextBox is disabled.

References

Promoted By Zergnet

Comments

You May Also Like

Related Searches

Check It Out

Geek Vs Geek: Robot battles, hoverboard drag race, and more

M
Is DIY in your DNA? Become part of our maker community.
Submit Your Work!