A MaskedTextBox control provides validation mechanism for user input on a Form. By default Masked property is set to None and the control works like a normal TextBox control.
How use MaskedTextBox Control
Drag and drop MaskedTextBox and Button (change its caption to Submit) control from toolbox on the window Form.

Code:
Public Class Form10
Private Sub Form10_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Here TextBox is masked as number show you can enter number only
MaskedTextBox1.Mask = "00000000000000000"
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Enter number will show in Label
Label2.Text = "Entered Number is " + MaskedTextBox1.Text
End Sub
End Class
Run The Project

When you enter other than number then masketextbox will not accept.Because in code mask is specified as MaskedTextBox1.Mask = "00000000000000000" which means it will accept only number.

When you enter number and click Submit Button then click event of submit button will fire and entered number will show in the Label.
MaskedTextBox Property
UseSystemPasswordChar: Gets or sets a value indicating as password character.
Private Sub Form10_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' entered number will show as password
MaskedTextBox1.UseSystemPasswordChar = True
End Sub

ForeColor:
ForeColor ofMaskedTextBox can be changed through ForeColor property of MaskedTextBox.
Private Sub Form10_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'change ForeColor of MaskedTextBox
MaskedTextBox1.ForeColor = Color.Red
End Sub
ForeColor of MaskedTextBox will bechanged.

Leave Comment
2 Comments