Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Text Property

MaskedTextBox.Text Property

Gets or sets the text as it is currently displayed to the user.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

[BindableAttribute(true)] 
[LocalizableAttribute(true)] 
public override string Text { get; set; }
/** @property */
public String get_Text ()

/** @property */
public void set_Text (String value)

public override function get Text () : String

public override function set Text (value : String)

Not applicable.

Property Value

A String containing the text currently displayed by the control. The default is an empty string.

Text is the default binding property for the MaskedTextBox class.

Strings retrieved using this property are formatted according to the control's formatting properties, such as Mask and TextMaskFormat.

You can assign a string with or without literal characters to Text depending on the values of ResetOnPrompt, ResetOnSpace, and SkipLiterals.

Text is the default binding property for MaskedTextBox.

MaskedTextBox will raise the TextChanged event whenever the formatted text value changes. Different properties may or may not cause this value to change. For example, changing the PasswordChar property will not raise the TextChanged event, but changing the Mask property will.

The following code example demonstrates the use of the Text property.

Private Sub DisplayText()
    Me.MaskedTextBox1.PasswordChar = CChar("*")

    Me.MaskedTextBox1.Mask = "000-00-0000" ' United States Social Security Number
    Me.MaskedTextBox1.Text = "999999999"

    Debug.WriteLine("MaskedControl.Text: " & Me.MaskedTextBox1.Text) ' Displays: 999-99-9
    Me.MaskedTextBox1.Text = ""

    ' Assigning text.
    Me.MaskedTextBox1.AllowPromptAsInput = True
    Me.MaskedTextBox1.Text = "999-99-9999" ' Works
    Me.MaskedTextBox1.Text = "999999999" ' Works
    Me.MaskedTextBox1.AllowPromptAsInput = False
    'Me.MaskedTextBox1.Text = "999-99-9999" ' Does not work
End Sub

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0

Community Additions

ADD
Show:
© 2015 Microsoft