Home » VB.NET TextBox Control

VB.NET TextBox Control

by Online Tutorials Library

VB.NET TextBox Control

A TextBox control is used to display, accept the text from the user as an input, or a single line of text on a VB.NET Windows form at runtime. Furthermore, we can add multiple text and scroll bars in textbox control. However, we can set the text on the textbox that displays on the form.

Let’s create a TextBox control in the VB.NET Windows form by using the following steps:

Step 1: We have to drag the TextBox control from the Toolbox and drop it on the Windows form, as shown below.

VB.NET TextBox Control

Step 2: Once the TextBox is added to the form, we can set various properties of the TextBox by clicking on the TextBox control.

VB.NET TextBox Properties

There are following properties of the TextBox control.

VB.NET TextBox Control

Properties Description
AutoCompleteMode It is used to get or set a value that indicates how the automatic completion works for the textbox control.
Font It is used to set the font style of the text displayed on a Windows form.
Lines It is used to set the number of lines in a TextBox control.
CharacterCasing It is used to get or set a value representing whether the TextBox control can modify the character’s case as they typed.
Multiline It is used to enter more than one line in a TextBox control, by changing the Multiline property value from False to True.
AcceptsReturn It is used to get or set a value that indicates whether pressing the enter button in a multiline textbox; it creates a new line of text in control.
PasswordChar It is used to set the password character that can be a mask in a single line of a TextBox control.
PreferredHeight It is used to set the preferred height of the textbox control in the window form.
ScrollBars It is used to display a scrollbar on a multiline textbox by setting a value for a Textbox control.
Text It is used to get or set the text associated with the textbox control.
Visible The Visible property sets a value that indicates whether the textbox should be displayed on a Windows Form.
WordWrap The WordWrap properties validate whether the multiline Textbox control automatically wraps words to the beginning of the next line when necessary.

VB.NET TextBox Events

Events Description
Click When a textbox is clicked, a click event is called in the textbox control.
CausesValidationChanged It occurs in the TextBox Control when the value of CauseValidation property is changed.
AcceptTabsChanged It is found in the TextBox control when the property value of the AcceptTab is changed.
BackColorChanged It is found in the TextBox Control when the property value of the BackColor is changed.
BorderStyleChanged It is found in the TextBox Control when the value of the BorderStyle is changed.
ControlAdded It is found when the new control is added to the Control.ControlCollection.
CursorChanged It is found in TextBox, when the textbox control is removed from the Control.ControlCollection.
FontChanged It occurs when the property of the Font is changed.
GetFocus It is found in TextBox control to get the focus.
MouseClick A MouseClick event occurs when the mouse clicks the control.
MultilineChanged It is found in a textbox control when the value of multiline changes.

Furthermore, we can also refer to the VB.NET Microsoft documentation to get a complete list of TextBox properties and events.

Let’s create a program that displays the login details.

tutoraspire1.vb

Output:

VB.NET TextBox Control

Now enter all the details of the User Login form, it shows the following image, as shown below.

VB.NET TextBox Control

Now, click on the Login button. It shows all the details filled by the user in the form.

VB.NET TextBox Control

The Exit button in the form used to terminate the program.


You may also like