TextBox. Users often need to enter text into programs. TextBox is the simplest way to implement this capability. We often used the Text property and its TextChanged event.
Getting started. Open a new VB.NET Windows Forms project in Visual Studio. Open the Toolbox, and then drag a TextBox control onto the window of your project.
Example program. A TextChanged event will be automatically inserted into your VB.NET code. This code is triggered whenever a character is typed (or deleted) from the TextBox.
Also If another part of the code changes the text of a TextBox, TextChanged will also be triggered.
Detail We cast the sender Object to a TextBox reference. You could use the TextBox1 directly in your code, but this is often less flexible.
Public Class Form1
Private Sub TextBox1_TextChanged(sender As Object,
e As EventArgs) Handles TextBox1.TextChanged
' Get TextBox reference from sender object.
' ... The TextBox1 could be used directly instead.
Dim t As TextBox = sender
' Assign the window's title to the Text of the TextBox.
' ... This is a string value.
Me.Text = t.Text
Some notes. The example shows some important principles of using TextBox. We almost always use the Text property on TextBox—and TextChanged tends to lead to clearer program logic.
Summary. A text box is used in almost all Windows Forms programs. It provides no formatting support (RichTextBox should be used when formatting is needed). But its simplicity is a benefit.