0% found this document useful (0 votes)
6 views

TextBox Control

Uploaded by

samu09160
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

TextBox Control

Uploaded by

samu09160
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

VB.

Net - TextBox Control


Text box controls allow entering text on a form at runtime. By default, it takes a single
line of text, however, you can make it accept multiple texts and even add scroll bars to it.

The Properties of the TextBox Control


The following are some of the commonly used properties of the TextBox control −

Property & Description

CharacterCasing
Gets or sets whether the TextBox control modifies the case of characters as they are
typed.

Font
Gets or sets the font of the text displayed by the control.

FontHeight
Gets or sets the height of the font of the control.

ForeColor
Gets or sets the foreground color of the control.

Lines
Gets or sets the lines of text in a text box control.

Multiline
Gets or sets a value indicating whether this is a multiline TextBox control.

PasswordChar
Gets or sets the character used to mask characters of a password in a single-line
TextBox control.

ReadOnly
Gets or sets a value indicating whether text in the text box is read-only.
ScrollBars
Gets or sets which scroll bars should appear in a multiline TextBox control. This
property has values −

 None
 Horizontal
 Vertical
 Both

TabIndex
Gets or sets the tab order of the control within its container.

Text
Gets or sets the current text in the TextBox.

TextAlign
Gets or sets how text is aligned in a TextBox control. This property has values −

 Left
 Right
 Center

TextLength
Gets the length of text in the control.

WordWrap
Indicates whether a multiline text box control automatically wraps words to the
beginning of the next line when necessary.

The Methods of the TextBox Control

Method Name & Description

AppendText
Appends text to the current text of a text box.
Clear
Clears all text from the text box control.

Copy
Copies the current selection in the text box to the Clipboard.

Cut
Moves the current selection in the text box to the Clipboard.

Paste
Replaces the current selection in the text box with the contents
of the Clipboard.

Paste(String)
Sets the selected text to the specified text without clearing the
undo buffer.

ResetText
Resets the Text property to its default value.

ToString
Returns a string that represents the TextBoxBase control.

Undo
Undoes th

Events of the TextBox Control


The following are some of the commonly used events of the Text control −

Event & Description

Click
Occurs when the control is clicked.
DoubleClick
Occurs when the control is double-clicked.

TextAlignChanged
Occurs when the TextAlign property value changes.

Example
In this example, we create three text boxes and use the Click event of a button to display the
entered text using a message box. Take the following steps −
 Drag and drop three Label controls and three TextBox controls on the form.
 Change the texts on the labels to: Name, Organization and Comments, respectively.
 Change the names of the text boxes to txtName, txtOrg and txtComment, respectively.
 Drag and drop a button control on the form. Set its name to btnMessage and its text
property to 'Send Message'.
 Click the button to add the Click event in the code window and add the following code.

Public Class Form1


Private Sub Form1_Load(sender As Object, e As EventArgs) _
' Set the caption bar text of the form.
Me.Text = "Welcome to Microsoft"
End Sub

Private Sub btnMessage_Click(sender As Object, e As EventArgs) _


MessageBox.Show("Thank you " + txtName.Text + " from " + txtOrg.Text)
End Sub
End Class

You might also like