Press "Enter" to skip to content

Working with TextBox Text and Label Text in VB

 Tip Abstraction:

        This Visual Basic tutorial describes how to programmatically change or edit the text of Textbox and Label

In previous lesson, we have learnt the basics of Visual basic and C# which contains how to create a new project and how to add tool elements into the window form. So we could add textboxes, label, buttons etc. but we have not programmed anything yet.

Let us start to write our VB program.

First of all, you have to understand that, we have to write our VB codes according to events.

What is an event? 

An event is an activity commonly caused by user or programmatically.
For example, if user clicks on a button, then that is an event.

Some of examples for event:

  • Button Double click
  • Key press by keyboard
  • Mouse Click
  • Form Load
  • Mouse Move
  • List box Item Selected
  • Combo box item Selection changed
  • etc.

So we have to write our VB code inside these events.

In previous lesson we created a Label (Name) and a TextBox.

The textbox has no value right now. So we are going to add a text on the textbox using our VB code.
We are going to add our code on form load event.

What is the Form load event:

This event is the activity when the form is loaded at first time. So if we add our VB code inside this event, then the code works whenever load the form.

How to open form load event:

It is very simple to open events on VB. You just double click on the form header or any blank space on the form.

VB taking form load event

Now you will get a code space like this:

VB form load event code

You have to write your VB codes inside this event code lines.

Before writing our codes, you must know the name of your tool elements such as Textbox and Label.

How do we get the elements’ name? 

We have added a label and a TextBox. To get the name of textbox, then go to its properties window (we have leant already how to get the properties window in our first lesson).


  • As we seen the text of label1 in first lesson, just look up for Name.
VB Textbox name property
  • Now it is ‘TextBox1’. We can change the name of any element. I just renamed into ‘username’.