当前位置: 首页>>代码示例>>C#>>正文


C# MaskedTextProvider.Set方法代码示例

本文整理汇总了C#中System.ComponentModel.MaskedTextProvider.Set方法的典型用法代码示例。如果您正苦于以下问题:C# MaskedTextProvider.Set方法的具体用法?C# MaskedTextProvider.Set怎么用?C# MaskedTextProvider.Set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.ComponentModel.MaskedTextProvider的用法示例。


在下文中一共展示了MaskedTextProvider.Set方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CoerceText

 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();            
 }
开发者ID:ittray,项目名称:LocalDemo,代码行数:7,代码来源:MaskedTextBox.cs

示例2: Formatar

        public static string Formatar(string valor, string mascara)
        {
            MaskedTextProvider mtpCnpj = new MaskedTextProvider(mascara);
            mtpCnpj.Set(valor);
            var formatted = mtpCnpj.ToString();
            if (formatted.IndexOf(" ") == -1) return formatted;

            mascara = mascara.Replace("0", "#").Replace(@"\", "");

            StringBuilder dado = new StringBuilder();
            foreach (char c in valor)
            {
                if (Char.IsNumber(c) || c == 'x' || c == 'X')
                    dado.Append(c);
            }

            int indMascara = mascara.Length;
            int indCampo = dado.Length;
            for (; indCampo > 0 && indMascara > 0; )
            {
                if (mascara[--indMascara] == '#')
                    indCampo -= 1;
            }

            StringBuilder saida = new StringBuilder();
            for (; indMascara < mascara.Length; indMascara++)
            {
                saida.Append((mascara[indMascara] == '#') ? dado[indCampo++] : mascara[indMascara]);
            }

            return saida.ToString();
        }
开发者ID:Didox,项目名称:MVC_e_Velocit_app,代码行数:32,代码来源:Funcoes.cs

示例3: FormatCNPJ

 /// <summary>
 /// formata o CNPJ
 /// </summary>
 /// <param name="cnpj">valor a ser formatado</param>
 /// <returns></returns>
 public static string FormatCNPJ(string cnpj)
 {
     string ret = "";
     MaskedTextProvider mascara;
     cnpj = Functions.OnlyNumbers(cnpj, "-.,/").ToString();
     //cnpj
     //##.###.###/####-##
     mascara = new MaskedTextProvider(@"00\.000\.000/0000-00");
     mascara.Set(cnpj);
     ret = mascara.ToString();
     return ret;
 }
开发者ID:akretion,项目名称:uninfe,代码行数:17,代码来源:CNPJ.cs

示例4: ForceText

 //force the text of the control to use the mask
 private static object ForceText(DependencyObject sender, object value)
 {
     MaskedTextBox textBox = (MaskedTextBox) sender;
     if (textBox.Mask != null)
     {
         MaskedTextProvider provider = new MaskedTextProvider(textBox.Mask);
         provider.Set((string) value);
         return provider.ToDisplayString();
     }
     else
     {
         return value;
     }
 }
开发者ID:XiBeichuan,项目名称:hydronumerics,代码行数:15,代码来源:MaskedTextBox.cs

示例5: MaskedTextBoxLoaded

        private void MaskedTextBoxLoaded(object sender, RoutedEventArgs e)
        {
            _provider = new MaskedTextProvider(!string.IsNullOrEmpty(InputMask) ? InputMask : " ", CultureInfo.CurrentCulture);

            _provider.Set(String.IsNullOrWhiteSpace(UnmaskedText) ? String.Empty : UnmaskedText);

            _provider.PromptChar = PromptChar;
            Text = _provider.ToDisplayString();

            DependencyPropertyDescriptor textProp = DependencyPropertyDescriptor.FromProperty(TextProperty,
                                                                                              typeof(MaskedTextBox));
            if (textProp != null)
            {
                textProp.AddValueChanged(this, (s, args) => UpdateText());
            }
            DataObject.AddPastingHandler(this, Pasting);
        }
开发者ID:khriza,项目名称:SambaPOS-3,代码行数:17,代码来源:MaskedTextBox.cs

示例6: CnDTimeInputTextBox

 public CnDTimeInputTextBox()
 {
     Mask = new CnDTimeInputMaskTimeWithMilliseconds();
     MaskProvider = new MaskedTextProvider(Mask.Mask);
     MaskProvider.Set(Mask.DefaultValue);
     RefreshText();
 }
开发者ID:CITnDev,项目名称:CnDTimeControls,代码行数:7,代码来源:CnDTimeInputTextBox.cs

示例7: GetMaskProvider

 private MaskedTextProvider GetMaskProvider()
 {
     MaskedTextProvider maskProvider = new MaskedTextProvider(Mask);
     maskProvider.Set(Text);
     return maskProvider;
 }
开发者ID:ittray,项目名称:LocalDemo,代码行数:6,代码来源:MaskedTextBox.cs

示例8: SetMaskedTextProvider

        /// <devdoc>
        ///     Overload to allow for passing the text when the mask is being changed from null,
        ///     in this case the maskedTextProvider holds backend info only (not the text).
        /// </devdoc>
        private void SetMaskedTextProvider( MaskedTextProvider newProvider, string textOnInitializingMask )
        {
            Debug.Assert( newProvider != null, "Initializing from a null MaskProvider ref." );
   
            // Set R/W properties.
            newProvider.IncludePrompt    = this.maskedTextProvider.IncludePrompt;
            newProvider.IncludeLiterals  = this.maskedTextProvider.IncludeLiterals;
            newProvider.SkipLiterals     = this.maskedTextProvider.SkipLiterals;
            newProvider.ResetOnPrompt    = this.maskedTextProvider.ResetOnPrompt;
            newProvider.ResetOnSpace     = this.maskedTextProvider.ResetOnSpace;

            // If mask not initialized and not initializing it, the new provider is just a property backend.
            // Change won't have any effect in text.
            if( this.flagState[IS_NULL_MASK] && textOnInitializingMask == null)
            {
                this.maskedTextProvider = newProvider;
                return;
            }

            int testPos = 0;
            bool raiseOnMaskInputRejected = false; // Raise if new provider rejects old text.
            MaskedTextResultHint hint = MaskedTextResultHint.NoEffect;
            MaskedTextProvider oldProvider = this.maskedTextProvider;
            
            // Attempt to add previous text.
            // If the mask is the same, we need to preserve the caret and character positions if the text is added successfully.
            bool preserveCharPos = oldProvider.Mask == newProvider.Mask;

            // Cache text output text before setting the new provider to determine whether we need to raise the TextChanged event.
            string oldText;

            // NOTE: Whenever changing the MTP, the text is lost if any character in the old text violates the new provider's mask.

            if( textOnInitializingMask != null ) // Changing Mask (from null), which is the only RO property that requires passing text.
            {
                oldText  = textOnInitializingMask;
                raiseOnMaskInputRejected = !newProvider.Set( textOnInitializingMask, out testPos, out hint );
            }
            else
            {
                oldText  = TextOutput;

                // We need to attempt to set the input characters one by one in the edit positions so they are not
                // escaped. 
                int assignedCount = oldProvider.AssignedEditPositionCount;
                int srcPos = 0;
                int dstPos = 0;

                while( assignedCount > 0 )
                {
                    srcPos = oldProvider.FindAssignedEditPositionFrom( srcPos, forward );
                    Debug.Assert( srcPos != MaskedTextProvider.InvalidIndex, "InvalidIndex unexpected at this time." );

                    if (preserveCharPos)
                    {
                        dstPos = srcPos;
                    }
                    else
                    {
                        dstPos = newProvider.FindEditPositionFrom(dstPos, forward);

                        if (dstPos == MaskedTextProvider.InvalidIndex)
                        {
                            newProvider.Clear();

                            testPos = newProvider.Length;
                            hint = MaskedTextResultHint.UnavailableEditPosition;
                            break;
                        }
                    }

                    if( !newProvider.Replace( oldProvider[srcPos], dstPos, out testPos, out hint ))
                    {
                        preserveCharPos = false;
                        newProvider.Clear();
                        break;
                    }

                    srcPos++;
                    dstPos++;
                    assignedCount--;
                }

                raiseOnMaskInputRejected = !MaskedTextProvider.GetOperationResultFromHint(hint);
            }


            // Set provider.
            this.maskedTextProvider = newProvider;

            if( this.flagState[IS_NULL_MASK] )
            {
                this.flagState[IS_NULL_MASK] = false;
            }

            // Raising events need to be done only after the new provider has been set so the MTB is in a state where properties 
//.........这里部分代码省略.........
开发者ID:krytht,项目名称:DotNetReferenceSource,代码行数:101,代码来源:MaskedTextBox.cs

示例9: IsValidStringAccordingMask

 /// <summary>
 /// Check if the received string value matches with the Introduction Mask for String datatype.
 /// </summary>
 /// <param name="stringValue">String to be checked.</param>
 /// <returns>Returns true if the received string matches with Introduction Mask.</returns>
 private bool IsValidStringAccordingMask(string stringValue)
 {
     bool result = true;
     if (Mask != string.Empty)
     {
         MaskedTextProvider maskTextProvider = new MaskedTextProvider(Mask);
         maskTextProvider.IncludeLiterals = false;
         maskTextProvider.Set(stringValue);
         result = maskTextProvider.VerifyString(stringValue) && maskTextProvider.MaskCompleted;
     }
     return result;
 }
开发者ID:sgon1853,项目名称:UPM_MDD_Thesis,代码行数:17,代码来源:MaskedTextBoxPresentation.cs

示例10: Set_string_TestException

		public void Set_string_TestException ()
		{
			MaskedTextProvider mtp = new MaskedTextProvider ("a");
			mtp.Set (null);
		}
开发者ID:peterdocter,项目名称:mono,代码行数:5,代码来源:MaskedTextProviderTest.cs

示例11: GetMaskedInput

 private string GetMaskedInput(string name, string primaryFieldFormat)
 {
     var provider = new MaskedTextProvider(primaryFieldFormat, CultureInfo.CurrentCulture);
     provider.Set(name);
     return provider.ToDisplayString();
 }
开发者ID:jgera,项目名称:SambaPOS-3,代码行数:6,代码来源:EntityType.cs

示例12: HasValue

 /// <summary>
 /// Checks if the editor has value or not.
 /// </summary>
 /// <returns>Return true if the editor has a value.</returns>
 private bool HasValue()
 {
     bool lResult = true;
     if (Mask != null && !Mask.Equals(string.Empty))
     {
         // Only String and Time data types can have masks in this Presentation. Check them separately.
         if (mDataType == ModelType.Time)
         {
             // Get the Time value without Time separators in order to check if the editor control has value.
             string lAuxStringValue = mMaskedTextBoxIT.Text.Replace(mMaskedTextBoxIT.Culture.DateTimeFormat.TimeSeparator, "");
             lResult = !string.IsNullOrEmpty(lAuxStringValue.Trim());
         }
         else
         {
             // String data type.
             MaskedTextProvider maskTextProvider = new MaskedTextProvider(Mask);
             maskTextProvider.IncludeLiterals = false;
             if (!maskTextProvider.VerifyString(mMaskedTextBoxIT.Text))
             {
                 // If the value assigned to the control does not satisfies the mask,
                 // check if the editor control Text has value.
                 lResult = (mMaskedTextBoxIT.Text != string.Empty);
             }
             else
             {
                 // If the value assigned satisfies the mask
                 // (it is not mandatory that the mask has been completed),
                 // assign the value to the MaskTextProvider and then check if
                 // it has value.
                 maskTextProvider.Set(mMaskedTextBoxIT.Text);
                 string auxString = maskTextProvider.ToString(false, false);
                 lResult = !string.IsNullOrEmpty(auxString);
             }
         }
     }
     else
     {
         lResult = !mMaskedTextBoxIT.Text.Equals(string.Empty);
     }
     return lResult;
 }
开发者ID:sgon1853,项目名称:UPM_MDD_Thesis,代码行数:45,代码来源:MaskedTextBoxPresentation.cs

示例13: Format

        /// <summary>
        /// Format the specified text using the specified mask, prompt
        /// character, and culture information and return the result
        /// values.
        /// </summary>
        /// <param name="mask">The mask to use.</param>
        /// <param name="text">The text to format.</param>
        /// <param name="promptChar">The prompt character to use for missing
        /// characters.  If a null character ('\x0') is specified, prompt
        /// characters are omitted.</param>
        /// <param name="culture">The culture information to use.  If null,
        /// the current culture is used.</param>
        /// <param name="hint">The result of formatting the text.</param>
        /// <param name="hintPosition">The position related to the result
        /// hint.</param>
        /// <returns>The formatted text string.</returns>
        public static string Format(string mask, string text, char promptChar,
          CultureInfo culture, out MaskedTextResultHint hint,
          out int hintPosition)
        {
            if(text == null)
                text = String.Empty;

            if(culture == null)
                culture = CultureInfo.CurrentCulture;

            MaskedTextProvider provider = new MaskedTextProvider(mask, culture);

            // Set the prompt character options
            if(promptChar != '\x0')
            {
                provider.PromptChar = promptChar;
                provider.IncludePrompt = true;
            }

            // Format and return the string
            provider.Set(text, out hintPosition, out hint);

            // Positive hint results are successful
            if(hint > 0)
                return provider.ToString();

            // Return the text as-is if it didn't fit the mask
            return text;
        }
开发者ID:chrisUsick,项目名称:BankOfBIT,代码行数:45,代码来源:MaskedLabel.cs

示例14: CnpjFormat

 public static string CnpjFormat(string cnpj)
 {
     var mtpCnpj = new MaskedTextProvider(@"00\.000\.000/0000-00");
     mtpCnpj.Set(LeadingZeros(cnpj, 11));
     return mtpCnpj.ToString();
 }
开发者ID:andreluizsombra,项目名称:Multiarkivos,代码行数:6,代码来源:StringFormatHelper.cs

示例15: Convert

    public object Convert( object value, Type targetType, object parameter, CultureInfo culture )
    {
      if( !targetType.IsAssignableFrom( typeof( string ) ) )
        return DependencyProperty.UnsetValue;

      string workingText = ( value == null ) ? string.Empty : value.ToString();

      string mask = null; // Defaults to no mask when no parameter is specified.

      if( parameter != null )
      {
        Type parameterType = parameter.GetType();
        if( parameterType == typeof( string ) )
        {
          string stringParameter = ( string )parameter;

          if( !string.IsNullOrEmpty( stringParameter ) )
            mask = stringParameter;
        }
        else
        {
          return DependencyProperty.UnsetValue;
        }
      }

      if( !string.IsNullOrEmpty( mask ) )
      {
        try
        {
          string rawText = string.Empty;

          CultureInfo currentCulture = CultureInfo.CurrentCulture;

          if( value != null )
          {
            try
            {
              Type valueDataType = value.GetType();

              MethodInfo valueToStringMethodInfo =
                valueDataType.GetMethod( "ToString", new Type[] { typeof( string ), typeof( IFormatProvider ) } );

              string formatSpecifier = MaskedTextBox.GetFormatSpecifierFromMask( mask, currentCulture );

              if( valueToStringMethodInfo != null )
              {
                rawText = ( string )valueToStringMethodInfo.Invoke( value, new object[] { formatSpecifier, currentCulture } );
              }
              else
              {
                rawText = value.ToString();
              }
            }
            catch
            {
              rawText = value.ToString();
            }
          }

          MaskedTextProvider maskedTextProvider = new MaskedTextProvider( mask, currentCulture );

          maskedTextProvider.Set( rawText );

          return maskedTextProvider.ToString( false, true );
        }
        catch
        {
        }
      }

      return value.ToString();
    }
开发者ID:wangws556,项目名称:duoduo-chat,代码行数:72,代码来源:ValueToMaskedTextConverter.cs


注:本文中的System.ComponentModel.MaskedTextProvider.Set方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。