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


C# ComponentModel.MaskedTextProvider类代码示例

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


MaskedTextProvider类属于System.ComponentModel命名空间,在下文中一共展示了MaskedTextProvider类的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: IsValidMaskDescriptor

 public static bool IsValidMaskDescriptor(MaskDescriptor maskDescriptor, out string validationErrorDescription)
 {
     validationErrorDescription = string.Empty;
     if (maskDescriptor == null)
     {
         validationErrorDescription = System.Design.SR.GetString("MaskDescriptorNull");
         return false;
     }
     if ((string.IsNullOrEmpty(maskDescriptor.Mask) || string.IsNullOrEmpty(maskDescriptor.Name)) || string.IsNullOrEmpty(maskDescriptor.Sample))
     {
         validationErrorDescription = System.Design.SR.GetString("MaskDescriptorNullOrEmptyRequiredProperty");
         return false;
     }
     MaskedTextProvider maskedTextProvider = new MaskedTextProvider(maskDescriptor.Mask, maskDescriptor.Culture);
     MaskedTextBox box = new MaskedTextBox(maskedTextProvider) {
         SkipLiterals = true,
         ResetOnPrompt = true,
         ResetOnSpace = true,
         ValidatingType = maskDescriptor.ValidatingType,
         FormatProvider = maskDescriptor.Culture,
         Culture = maskDescriptor.Culture
     };
     box.TypeValidationCompleted += new TypeValidationEventHandler(MaskDescriptor.maskedTextBox1_TypeValidationCompleted);
     box.MaskInputRejected += new MaskInputRejectedEventHandler(MaskDescriptor.maskedTextBox1_MaskInputRejected);
     box.Text = maskDescriptor.Sample;
     if ((box.Tag == null) && (maskDescriptor.ValidatingType != null))
     {
         box.ValidateText();
     }
     if (box.Tag != null)
     {
         validationErrorDescription = box.Tag.ToString();
     }
     return (validationErrorDescription.Length == 0);
 }
开发者ID:Reegenerator,项目名称:Sample-CustomizeDatasetCS,代码行数:35,代码来源:MaskDescriptor.cs

示例4: PasswordTest

		public void PasswordTest ()
		{

			MaskedTextProvider mtp = new MaskedTextProvider ("abcd", CultureInfo.GetCultureInfo ("es-AR"), false, '>', '^', false); 
			Assert.AreEqual (" bcd", mtp.ToString (), "#A1");
			
		}
开发者ID:peterdocter,项目名称:mono,代码行数:7,代码来源:MaskedTextProviderTest.cs

示例5: Clear

 public void Clear()
 {
     base.CanRaiseFilterChanged = false;
     this.tsmiComparisionContains.PerformClick();
     this.MaskProvider = new MaskedTextProvider("aa", CultureInfo.InvariantCulture, true);
     this.tstbHex.Text = this.MaskProvider.ToDisplayString();
     base.CanRaiseFilterChanged = true;
 }
开发者ID:shankithegreat,项目名称:commanderdotnet,代码行数:8,代码来源:HexContentFilterControl.cs

示例6: HexContentFilterControl

 public HexContentFilterControl()
 {
     this.components = null;
     this.InitializeComponent();
     this.InitializeToolStripItems();
     this.Clear();
     this.MaskProvider = new MaskedTextProvider("aa", CultureInfo.InvariantCulture, true);
 }
开发者ID:shankithegreat,项目名称:commanderdotnet,代码行数:8,代码来源:HexContentFilterControl.cs

示例7: AutoCompletingMaskEventArgs

    public AutoCompletingMaskEventArgs( MaskedTextProvider maskedTextProvider, int startPosition, int selectionLength, string input )
    {
      m_autoCompleteStartPosition = -1;

      m_maskedTextProvider = maskedTextProvider;
      m_startPosition = startPosition;
      m_selectionLength = selectionLength;
      m_input = input;
    }
开发者ID:Alexz18z35z,项目名称:Gibbo2D,代码行数:9,代码来源:AutoCompletingMaskEventArgs.cs

示例8: 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

示例9: 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

示例10: DefaultCultureTest

		public void DefaultCultureTest ()
		{
			CultureInfo currentUI = Thread.CurrentThread.CurrentUICulture;
			CultureInfo current = Thread.CurrentThread.CurrentCulture;

			try {
				Thread.CurrentThread.CurrentUICulture = new CultureInfo ("en-US");
				Thread.CurrentThread.CurrentCulture = new CultureInfo ("es-ES");
				MaskedTextProvider mtp = new MaskedTextProvider ("mask");
				Assert.AreEqual ("es-ES", mtp.Culture.Name, "#01");
			} finally {
				Thread.CurrentThread.CurrentCulture = current;
				Thread.CurrentThread.CurrentUICulture = currentUI;
			}
		}
开发者ID:peterdocter,项目名称:mono,代码行数:15,代码来源:MaskedTextProviderTest.cs

示例11: 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

示例12: PlaceChar

        /// <devdoc>
        ///     Override version to be able to perform the operation on a cloned provider.
        /// </devdoc>
        private bool PlaceChar(MaskedTextProvider provider, char ch, int startPosition, int length, bool overwrite, 
            out MaskedTextResultHint hint)
        {
            Debug.Assert( !this.flagState[IS_NULL_MASK], "This method must be called when a Mask is provided." );

            this.caretTestPos = startPosition;

            if (startPosition < this.maskedTextProvider.Length)
            {
                if (length > 0)  // Replacing selection with input char.
                {
                    int endPos = startPosition + length - 1;
                    return provider.Replace(ch, startPosition, endPos, out this.caretTestPos, out hint);
                }
                else
                {
                    if (overwrite)
                    {
                        // overwrite character at next edit position from startPosition (inclusive).
                        return provider.Replace(ch, startPosition, out this.caretTestPos, out hint);
                    }
                    else // insert.
                    {
                        return provider.InsertAt(ch, startPosition, out this.caretTestPos, out hint);
                    }
                }
            }

            hint = MaskedTextResultHint.UnavailableEditPosition;
            return false;
        }
开发者ID:krytht,项目名称:DotNetReferenceSource,代码行数:34,代码来源:MaskedTextBox.cs

示例13: Replace

        /// <devdoc>
        ///     Replaces the current selection in the text box specified by the startPosition and selectionLen parameters
        ///     with the contents of the supplied string.
        /// </devdoc>
        private void Replace(string text, int startPosition, int selectionLen)
        {
            Debug.Assert( !this.flagState[IS_NULL_MASK], "This method must be called when a Mask is provided." );
            Debug.Assert(text != null, "text is null.");

            // Clone the MaskedTextProvider so text properties are not modified until the paste operation is
            // completed.  This is needed in case one of these properties is retreived in a MaskedInputRejected
            // event handler (clipboard text is attempted to be set into the input text char by char).

            MaskedTextProvider clonedProvider = (MaskedTextProvider) this.maskedTextProvider.Clone();

            // Cache the current caret position so we restore it in case the text does not change. VSW#498875.
            int currentCaretPos = this.caretTestPos;

            // First replace characters in the selection (if any and if any edit positions) until completed, or the test position falls 
            // outside the selection range, or there's no more room in the test string for editable characters.
            // Then insert any remaining characters from the input.

            MaskedTextResultHint hint = MaskedTextResultHint.NoEffect;
            int endPos = startPosition + selectionLen - 1;

            if( this.RejectInputOnFirstFailure )
            {
                bool succeeded; 

                succeeded = (startPosition > endPos) ?
                    clonedProvider.InsertAt(text, startPosition, out this.caretTestPos, out hint ) :
                    clonedProvider.Replace(text, startPosition, endPos, out this.caretTestPos, out hint);

                if( !succeeded )
                {
                    OnMaskInputRejected(new MaskInputRejectedEventArgs(this.caretTestPos, hint));
                }
            }
            else
            {
                // temp hint used to preserve the 'primary' operation hint (no side effects).
                MaskedTextResultHint tempHint = hint;
                int testPos;
                
                foreach (char ch in text)
                {
                    if( !this.maskedTextProvider.VerifyEscapeChar( ch, startPosition ))  // char won't be escaped, find and edit position for it.
                    {
                        // Observe that we look for a position w/o respecting the selection length, because the input text could be larger than
                        // the number of edit positions in the selection.
                        testPos = clonedProvider.FindEditPositionFrom(startPosition, forward);

                        if( testPos == MaskedTextProvider.InvalidIndex )
                        {
                            // this will continue to execute (fail) until the end of the text so we fire the event for each remaining char.
                            OnMaskInputRejected(new MaskInputRejectedEventArgs(startPosition, MaskedTextResultHint.UnavailableEditPosition));
                            continue;
                        }

                        startPosition = testPos;
                    }

                    int length = endPos >= startPosition ? 1 : 0;

                    // if length > 0 we are (re)placing the input char in the current startPosition, otherwise we are inserting the input.
                    bool replace = length > 0;

                    if (PlaceChar(clonedProvider, ch, startPosition, length, replace, out tempHint))
                    {
                        // caretTestPos is updated in PlaceChar call.
                        startPosition = this.caretTestPos + 1;

                        // place char will insert or replace a single character so the hint must be success, and that will be the final operation
                        // result hint.
                        if (tempHint == MaskedTextResultHint.Success && hint != tempHint)
                        {
                            hint = tempHint;
                        }
                    }
                    else
                    {
                        OnMaskInputRejected(new MaskInputRejectedEventArgs(startPosition, tempHint));
                    }
                }

                if (selectionLen > 0)
                {
                    // At this point we have processed all characters from the input text (if any) but still need to 
                    // remove remaining characters from the selected text (if editable and valid chars).

                    if (startPosition <= endPos)
                    {
                        if (!clonedProvider.RemoveAt(startPosition, endPos, out this.caretTestPos, out tempHint))
                        {
                            OnMaskInputRejected(new MaskInputRejectedEventArgs(this.caretTestPos, tempHint));
                        }

                        // If 'replace' is not actually performed (maybe the input is empty which means 'remove', hint will be whatever
                        // the 'remove' operation result hint is.
                        if (hint == MaskedTextResultHint.NoEffect && hint != tempHint)
//.........这里部分代码省略.........
开发者ID:krytht,项目名称:DotNetReferenceSource,代码行数:101,代码来源:MaskedTextBox.cs

示例14: Initialize

        /// <devdoc>
        ///     Initializes the object with the specified MaskedTextProvider object and default
        ///     property values.
        /// </devdoc>
        private void Initialize(MaskedTextProvider maskedTextProvider)
        {
            Debug.Assert(maskedTextProvider != null, "Initializing from a null MaskProvider ref.");

            this.maskedTextProvider = maskedTextProvider;

            // set the initial display text.
            if (!this.flagState[IS_NULL_MASK])
            {
                SetWindowText();
            }

            // set default values.
            this.passwordChar = this.maskedTextProvider.PasswordChar;
            this.insertMode   = InsertKeyMode.Default;

            this.flagState[HIDE_PROMPT_ON_LEAVE         ] = false;
            this.flagState[BEEP_ON_ERROR                ] = false;
            this.flagState[USE_SYSTEM_PASSWORD_CHAR     ] = false;
            this.flagState[REJECT_INPUT_ON_FIRST_FAILURE] = false;

            // CutCopyMaskFormat - set same defaults as TextMaskFormat (IncludePromptAndLiterals).
            // It is a lot easier to handle this flags individually since that's the way the MaskedTextProvider does it.
            this.flagState[CUTCOPYINCLUDEPROMPT         ] = this.maskedTextProvider.IncludePrompt;
            this.flagState[CUTCOPYINCLUDELITERALS       ] = this.maskedTextProvider.IncludeLiterals;

            // fields for internal use.
            this.flagState[HANDLE_KEY_PRESS] = true;
            this.caretTestPos           = 0; 
        }
开发者ID:krytht,项目名称:DotNetReferenceSource,代码行数:34,代码来源:MaskedTextBox.cs

示例15: MaskedTextBox

        /// <devdoc>
        ///     Constructs the MaskedTextBox with the specified MaskedTextProvider object.
        /// </devdoc>
        public MaskedTextBox(MaskedTextProvider maskedTextProvider)
        {
            if (maskedTextProvider == null)
            {
                throw new ArgumentNullException();
            }

            this.flagState[IS_NULL_MASK] = false;
            Initialize(maskedTextProvider);
        }
开发者ID:krytht,项目名称:DotNetReferenceSource,代码行数:13,代码来源:MaskedTextBox.cs


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