How to Change the TextBox Border Color in Visual Basic

Written by alan hughes
  • Share
  • Tweet
  • Share
  • Pin
  • Email
How to Change the TextBox Border Color in Visual Basic
Use Visual Basic's RectangleShape control to highlight a TextBox border. (Stockbyte/Stockbyte/Getty Images)

Microsoft's Visual Basic allows user input via the TextBox control, and the various properties of the control allow the programmer to make changes to the visual effects of the TextBox. Although there is no border-colour property for a TextBox control in Visual Basic, there is a way to accomplish the desired effect using the program's Power Pack RectangleShape control.

Skill level:
Moderately Easy


  1. 1

    Start Microsoft Visual Basic and click "New Project" on the Start page, then double-click on "Windows Forms Application" to open a new blank form.

  2. 2

    Click on the "Toolbox" tab on the left of the Design window to open the Toolbox.

  3. 3

    Double-click on the "Button" control twice to add two buttons to the form. Double-click on the "TextBox" control to add a TextBox to the form. Scroll down in the Toolbox to the "Power Pack" menu item and double-click on the "RectangleShape" control to add a rectangle to the form.

  4. 4

    Click on the form to close the Toolbox and arrange the buttons on the form. Drag the TextBox to the middle of the form and drag the RectangleShape over the TextBox and align the two so that the RectangleShape displays on the border of the TextBox. This allows the RectangleShape to serve as the border for the TextBox.

  5. 5

    Double-click on "Button1" to open the Code window and place the cursor in the "Button1_click" event procedure. Add the following code between the two lines:

    RectangleShape1.BorderColor = Color.Red

    This will cause the RectangleShape1 border to change to the colour red, which will give the appearance of a red border around the TextBox. Repeat this process for "Button2," changing the "Color.Red" to "Color.Green."

  6. 6

    Click on the "Debug" menu item at the top of the screen and select the "Start Debugging" option. This will bring up your form in test mode. Click "Button1" and the border around the TextBox should turn red. Click "Button2" and the border around the TextBox should turn green.

Don't Miss

  • All types
  • Articles
  • Slideshows
  • Videos
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

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