Open In App

How to set Text in MaskedTextBox in C#?

In C#, MaskedTextBox control gives a validation procedure for the user input on the form like date, phone numbers, etc. Or in other words, it is used to provide a mask which differentiates between proper and improper user input. In MaskedTextBox control, you can set the text in the MaskedTextBox using the Text Property which will be displayed to the user. It is a default binding property for MaskedTextBox class. The strings retrieve from this property are formatted using the format properties like Mask, TextMaskFormat, etc. You can set this property in two different ways:

1. Design-Time: It is the easiest way to set the text in the MaskedTextBox as shown in the following steps:



2. Run-Time: It is a little bit trickier than the above method. In this method, you can set the text in the MaskedTextBox control programmatically with the help of given syntax:

public override string Text { get; set; }

The value of this property is of System.String type, which is will be displayed to the user. The default value of this property is empty. The following steps show how to set the text in the MaskedTextBox dynamically:


Article Tags :
C#