What is TextBox Control in VB.net?
A TextBox Control in VB.net is used to show, and take text from the user as input, or a single line of text on a VB.net Windows form at runtime.
Additionally, the VB.net Textbox Control allows us to add additional text and scroll bars.
On the other hand, we can modify the text that appears in the form’s textbox.
Let’s create a text box by dragging a Text Box control from the Toolbox and dropping it on the form.
Properties of the TextBox Control in VB.net
The following are some of the commonly used Properties of the TextBox control in VB.net.
|#||Properties of the TextBox Control in VB.net||Description|
|1.||AutoCompleteMode||It is used to get or set a value that indicates how the automatic completion works for the textbox control.|
|2.||Font||It is used to set the font style of the text displayed on a Windows form.|
|3.||Lines||It is used to set the number of lines in a TextBox control.|
|4.||CharacterCasing||It is used to get or set a value representing whether the TextBox control can modify the character’s case as they typed.|
|5.||Multiline||It is used to enter more than one line in a TextBox control, by changing the Multiline property value from False to True.|
|6.||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.|
|7.||PasswordChar||It is used to set the password character that can be a mask in a single line of a TextBox control.|
|8.||PreferredHeight||It is used to set the preferred height of the textbox control in the window form.|
|9.||ScrollBars||It is used to display a scrollbar on a multiline textbox by setting a value for a Textbox control.|
|10.||Text||It is used to get or set the text associated with the textbox control.|
|11.||Visible||The Visible property sets a value that indicates whether the textbox should be displayed on a Windows Form.|
|12.||WordWrap||The WordWrap properties validate whether the multiline Textbox control automatically wraps words to the beginning of the next line when necessary.|
|13.||AutoCompleteCustomSource||Gets or sets a custom System.Collections.Specialized.StringCollection to use when the AutoCompleteSourceproperty is set to CustomSource.|
|14.||AutoCompleteSource||Gets or sets a value specifying the source of complete strings used for automatic completion.|
|15.||FontHeight||Gets or sets the height of the font of the control.|
|16.||ForeColor||Gets or sets the foreground color of the control.|
|17.||TabIndex||Gets or sets the tab order of the control within its container.|
|18.||TextAlign||Gets or sets how text is aligned in a TextBox control.|
|19.||TextLength||Gets the length of text in the control.|
Methods of the TextBox Control in VB.net
The following are some of the commonly used Methods of TextBox Control in VB.net.
|#||Methods of the TextBox Control in VB.net||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 in VB.net
The following are some of the commonly used Events of the Text control in VB.net.
|#||Events of the TextBox Control in VB.net||Description|
|1.||Click||When a textbox is clicked, a click event is called in the textbox control.|
|2.||CausesValidationChanged||It occurs in the TextBox Control when the value of CauseValidation property is changed.|
|3.||AcceptTabsChanged||It is found in the TextBox control when the property value of the AcceptTab is changed.|
|4.||BackColorChanged||It is found in the TextBox Control when the property value of the BackColor is changed.|
|5.||BorderStyleChanged||It is found in the TextBox Control when the value of the BorderStyle is changed.|
|6.||ControlAdded||It is found when the new control is added to the Control.ControlCollection.|
|7.||CursorChanged||It is found in TextBox, when the textbox control is removed from the Control.ControlCollection.|
|8.||FontChanged||It occurs when the property of the Font is changed.|
|9.||GetFocus||It is found in TextBox control to get the focus.|
|10.||MouseClick||A MouseClick event occurs when the mouse clicks the control.|
|11.||MultilineChanged||It is found in a textbox control when the value of multiline changes.|
Let’s create a program that displays the login details.
Public Class Form1 Private Sub Button1_Click(sender As Object, e As EventArgs) End Sub Private Sub Button1_Click_1(sender As Object, e As EventArgs) Handles Button1.Click ' Display the user details, when the Button1 is clicked MsgBox(" Your Name: " & sname.Text + vbCrLf + "Your Address: " & address.Text + vbCrLf + "Your Course: " & course.Text) End Sub Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load End Sub End Class
Now enter all the details of the student registration form, it shows the following image, as shown below.
Now, click on the Register button. It shows all the details filled in by the user in the form.
The TextBox Control allows you to enter text into your form during runtime. It is good for getting input from users.
The default setting is that the TextBox Control will only accept one line of text.
However, it is possible for you to change this. You can hide what the user types into the TextBox, especially when you need to capture passwords.
You can also set the maximum number of characters that you need to be entered into the TextBox.
You can make your TextBox un-editable, meaning that the users won’t be able to change the text displayed on it.
- Form Controls in VB.net – Windows Form Controls in VB.net
- Basic Controls in VB.net – What are the Basic Controls in VB.net
- Button Control in VB.net – Windows Form Button Control in VB.net
- Label Control in VB.net – What is Label Control in VB.net