How to Disable/Enable Command Buttons in VB.net on the KeyUp Routine

Written by jim campbell
  • Share
  • Tweet
  • Share
  • Email

Each time a user presses a key on the keyboard, the "KeyDown" and "KeyUp" events trigger in a VB.NET application. You can use these events to disable and enable a form button. Coding for this event means the button's active state will toggle each time a user presses a key.

Skill level:
Moderate

Other People Are Reading

Instructions

  1. 1

    Click the Windows "Start" button and select "All Programs." Click "Microsoft .NET," then click "Visual Studio" to open the VB.NET programming software.

  2. 2

    Double-click the project file name in the list of recent projects to load the code. After the code pages load, right-click the form you want to use to monitor keyboard activity. Click "View Code" to open the form's code file.

  3. 3

    Scroll down to the line of code labelled "Public Event KeyUp As KeyEventHandler." This code starts the function. You will place your button code after this line of code.

  4. 4

    Type the following command to disable the button:

    button1.Enabled = False

    Activating this code "grays out" the button, so it is not active but visible for the user.

  5. 5

    Type the following code to enable the button:

    button1.Enabled = True

    The code above returns the button to its active, clickable state.

Don't Miss

Filter:
  • All types
  • Articles
  • Slideshows
  • Videos
Sort:
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the eHow.co.uk site, you consent to the use of cookies. For more information, please see our Cookie policy.