System.ComponentModel.MaskedTextProvider.ToDisplayString C# (CSharp) Method

ToDisplayString() public method

Returns a formatted string based on the mask, honoring only the PasswordChar property. prompt character and literals are always included. This is the text to be shown in a control when it has the focus.
public ToDisplayString ( ) : string
return string
        public string ToDisplayString()
        {
            if (!IsPassword || _assignedCharCount == 0) // just return the testString since it contains the formatted text.
            {
                return _testString.ToString();
            }

            // Copy test string and replace edit chars with password.
            StringBuilder st = new StringBuilder(_testString.Length);

            for (int position = 0; position < _testString.Length; position++)
            {
                CharDescriptor chDex = _stringDescriptor[position];
                st.Append(IsEditPosition(chDex) && chDex.IsAssigned ? _passwordChar : _testString[position]);
            }

            return st.ToString();
        }

Usage Example

Example #1
1
 private static object CoerceText(DependencyObject d, object value)
 {
     MaskedTextBox textBox = (MaskedTextBox)d;
     MaskedTextProvider maskProvider = new MaskedTextProvider(textBox.Mask);
     maskProvider.Set((string)value);
     return maskProvider.ToDisplayString();            
 }
All Usage Examples Of System.ComponentModel.MaskedTextProvider::ToDisplayString