TextBox Control


VB.Net-Informations.com
SiteMap

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-textbox.jpg

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

  TextBox1.Text = "http://vb.net-informations.com"

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

  Dim var As String

var = TextBox1.Text

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.

  TextBox1.ReadOnly = True

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.

  TextBox1.Multiline = True

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.

  TextBox1.PasswordChar = "*"

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

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
		MsgBox(var)
	End Sub

End Class







More Source Code :
|  Home  |   VB.NET  |   C#  |   ASP.NET  |   SiteMap  |   Terms of Use  |   About  |