---
title: "MaskedTextBox Control in VB.Net"  
description: "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"  
author: "Pushpendra Singh"  
published: 2010-12-12  
updated: 2020-03-15  
canonical: https://www.mindstick.com/articles/305/maskedtextbox-control-in-vb-dot-net  
category: "vb.net"  
tags: ["vb.net"]  
reading_time: 2 minutes  

---

# MaskedTextBox Control in VB.Net

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.

![MaskedTextBox Control in VB.Net](https://www.mindstick.com/mindstickarticle/8a955dfa-6b51-494d-be88-ec5751963bc0/images/3d224e27-2b11-45ef-ba86-8bb693fe278c.png)

##### 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 SubEnd Class
```

##### Run The Project

![MaskedTextBox Control in VB.Net](https://www.mindstick.com/mindstickarticle/8a955dfa-6b51-494d-be88-ec5751963bc0/images/1f7e2dde-3304-4b65-900a-fab3d4217c56.png)

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.

![MaskedTextBox Control in VB.Net](https://www.mindstick.com/mindstickarticle/8a955dfa-6b51-494d-be88-ec5751963bc0/images/15d885ca-1c11-4aa4-befd-a1cc41a5c4b4.png)

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 = TrueEnd Sub
```

\

![MaskedTextBox Control in VB.Net](https://www.mindstick.com/mindstickarticle/8a955dfa-6b51-494d-be88-ec5751963bc0/images/e02cf4df-e858-401c-9777-48393bf53ef9.png)

##### 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.RedEnd Sub
```

ForeColor of MaskedTextBox will bechanged.

![MaskedTextBox Control in VB.Net](https://www.mindstick.com/mindstickarticle/8a955dfa-6b51-494d-be88-ec5751963bc0/images/8a70a6af-89aa-498e-84fd-f9f6d904ea1d.png)

\

---

Original Source: https://www.mindstick.com/articles/305/maskedtextbox-control-in-vb-dot-net

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
