TextBox Control

VB.Net provides several mechanisms for gathering input in a program. A TextBox control is used to display, or accept as input, a single line of text.

VB.Net programmers make extensive use of the TextBox control to let the user view or enter large amount of text. A text box object is used to display text on a form or to get user input while a VB.Net program is running. In a text box, a user can type data or paste it into the control from the clipboard.

For displaying a text in a TextBox control , you can code like this.

You can also collect the input value from a TextBox control to a variable like this way.

VB.Net TextBox Properties

You can set TextBox properties through Property window or through program. Normally Property window is located under the solution explorer. You can open Properties window by pressing F4 or right click on a control and select Properties menu item. textbox properties

The below code set a textbox width as 150 and height as 25 through source code.

Background Color and Foreground Color

You can set Textbox background color and foreground color through property window, also you can set it programmatically.

TextBox BorderStyle

You can set 3 different types of border style for textbox in, they are None, FixedSingle and fixed3d.

VB.Net TextBox Events

TextBox Keydown event

Keydown event occurs when a key is pressed while the control has focus.


TextChanged Event

TextChanged Event is raised if the Text property is changed by either through program modification or user input.


VB.Net Textbox Maximum Length

Maximum Length property sets the maximum number of characters or words the user can input into the text box control. That means you can limit the user input by this property.

How to ReadOnly Textbox

when a program wants to prevent a user from changing the text that appears in a text box, the program can set the controls Readonly property is to True.

Multiline TextBox in

By default TextBox accept single line of characters , If you need to enter more than one line in a TextBox control, you should change the Multiline property is to True.

Textbox passowrd character

Sometimes you want a textbox to receive password from the user. In order to keep the password confidential, you can set the PasswordChar property of a textbox to a specific character.

The above code set the PasswordChar to * , so when the user enter password then it display only * instead of typed characters.

How to Newline in TextBox

You can add new line in a textbox using two ways.


How to retrieve integer values from textbox ?

VB.Net String to Integer conversion

Parse method Converts the string representation of a number to its integer equivalent.

VB.Net String to Double conversion

How to allow only numbers in a textbox

Many of us have faced a situation where we want the user to enter a number in a TextBox. Click the following link that are going to make a Numeric Textbox which will accept only numeric values; if there are any values except numeric. More about.... How do I make a textbox that only accepts numbers

VB.Net Autocomplete TextBox

Autocomplete TextBox in VB.Net

From the latest version of Visual Studio, some of the controls support Autocomplete feature including the TextBox controls. The properties like AutoCompleteCustomSource, AutoCompleteMode and AutoCompleteSource to perform a TextBox that automatically completes user input strings by comparing the prefix letters being entered to the prefixes of all strings in a data source. More about.... VB.Net Autocomplete TextBox

From the following VB.Net source code you can see some important property settings to a TextBox control.

Public Class Form1

	Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
		TextBox1.Width = 200
		TextBox1.Height = 50
		TextBox1.Multiline = True
	End Sub

	Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
		Dim var As String
		var = TextBox1.Text
	End Sub

End Class (C) 2021    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.
SiteMap  | Terms  | About