Skip to main content

What are the properties of TextBox in Visual Basic?

         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.
Let's create a text box by dragging a Text Box control from the Toolbox and dropping it on the form.

    VB.Net Text Box Control

The Properties of the TextBox Control

The following are some of the commonly used properties of the TextBox control −
Sr.No. Property & Description
1 AcceptsReturn

Gets or sets a value indicating whether pressing ENTER in a multiline TextBox control creates a new line of text in the control or activates the default button for the form.
2 AutoCompleteCustomSource

Gets or sets a custom System.Collections.Specialized.StringCollection to use when the AutoCompleteSourceproperty is set to CustomSource.
3 AutoCompleteMode

Gets or sets an option that controls how automatic completion works for the TextBox.
4 AutoCompleteSource

Gets or sets a value specifying the source of complete strings used for automatic completion.
5 CharacterCasing

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

Gets or sets the font of the text displayed by the control.
7 FontHeight

Gets or sets the height of the font of the control.
8 ForeColor

Gets or sets the foreground color of the control.
9 Lines

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

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

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

Gets or sets a value indicating whether text in the text box is read-only.
13 ScrollBars

Gets or sets which scroll bars should appear in a multiline TextBox control. This property has values −
  • None
  • Horizontal
  • Vertical
  • Both
14 TabIndex

Gets or sets the tab order of the control within its container.
15 Text
Gets or sets the current text in the TextBox.
16 TextAlign

Gets or sets how text is aligned in a TextBox control. This property has values −
  • Left
  • Right
  • Center
17 TextLength

Gets the length of text in the control.
18 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

The following are some of the commonly used methods of the TextBox control −
Sr.No. Method Name & Description
1 AppendText

Appends text to the current text of a text box.
2 Clear
Clears all text from the text box control.
3 Copy
Copies the current selection in the text box to the Clipboard.
4 Cut
Moves the current selection in the text box to the Clipboard.
5 Paste
Replaces the current selection in the text box with the contents of the Clipboard.
6 Paste(String)
Sets the selected text to the specified text without clearing the undo buffer.
7 ResetText

Resets the Text property to its default value.
8 ToString

Returns a string that represents the TextBoxBase control.
9 Undo
Undoes the last edit operation in the text box.

Events of the TextBox Control

The following are some of the commonly used events of the Text control −
Sr.No. Event & Description
1 Click
Occurs when the control is clicked.
2 DoubleClick

Occurs when the control is double-clicked.
3 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) _
       Handles MyBase.Load
      ' Set the caption bar text of the form.  
      Me.Text = "quoranzers.blogspot.com"
   End Sub
    
   Private Sub btnMessage_Click(sender As Object, e As EventArgs) _Handles btnMessage.Click 
 
   MessageBox.Show("Thank you " + txtName.Text + " from " + txtOrg.Text)
 
   End Sub
End Class
 
When the above code is executed and run using Start button available at the Microsoft Visual Studio tool bar, it will show the following window −

Result Form

Clicking the Send Message button would show the following message box −

Result Form

 

Comments

Popular posts from this blog

How can we lose weight by eating fruits and cereals?

Now we can split fruits and cereals in two parts. First we are going to look how fruits help in weight loss.Here the list of 11 fruits that help to loss wight. Fruit is nature's ready-made snack packed with vitamins, fiber, and other nutrients that support a healthy diet. Fruit is also generally low in calories and high in fiber, which may help you lose weight. In fact, eating fruit is linked to a lower body weight and a lower risk of diabetes, high blood pressure, cancer, and heart disease. Here are 11 of the best fruits to eat for weight loss. 1. Grapefruit Grapefruit is a cross between a pomelo and an orange and is commonly associated with dieting and weight loss.    Half a grapefruit contains just 39 calories but provides 65% of the reference daily intake (RDI) for of vitamin C. Red varieties also provide 28% of the RDI for vitamin A ( 1 Trusted Source ).  What's more, grapefruit has a low glycemic index (GI), which means it r...

Can I create tab control in vb.net without using toolbox control?

First we create a form in vb and we are going to add a tab by coding. Code is Here tab is created when form loads..... the output is as follows.. Now we can add some controls to each tab. in tab page1 a text box in tab page2 a combobox in tab page3 a listbox in tabpage4 a button. The code is The output is as follows