當前位置: 首頁>>代碼示例>>C#>>正文


C# MaskedTextProvider.FindEditPositionFrom方法代碼示例

本文整理匯總了C#中System.ComponentModel.MaskedTextProvider.FindEditPositionFrom方法的典型用法代碼示例。如果您正苦於以下問題:C# MaskedTextProvider.FindEditPositionFrom方法的具體用法?C# MaskedTextProvider.FindEditPositionFrom怎麽用?C# MaskedTextProvider.FindEditPositionFrom使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.ComponentModel.MaskedTextProvider的用法示例。


在下文中一共展示了MaskedTextProvider.FindEditPositionFrom方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

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

示例2: CanReplace

        internal virtual bool CanReplace( MaskedTextProvider provider, string text, int startPosition, int selectionLength, bool rejectInputOnFirstFailure, out int tentativeCaretIndex )
        {
            int endPosition = ( startPosition + selectionLength ) - 1;
              tentativeCaretIndex = -1;

              bool success = false;

              foreach( char ch in text )
              {
            if( !m_maskedTextProvider.VerifyEscapeChar( ch, startPosition ) )
            {
              int editPositionFrom = provider.FindEditPositionFrom( startPosition, true );

              if( editPositionFrom == MaskedTextProvider.InvalidIndex )
            break;

              startPosition = editPositionFrom;
            }

            int length = ( endPosition >= startPosition ) ? 1 : 0;
            bool overwrite = length > 0;

            if( this.PlaceChar( provider, ch, startPosition, length, overwrite, out tentativeCaretIndex ) )
            {
              // Only one successfully inserted character is enough to declare the replace operation successful.
              success = true;

              startPosition = tentativeCaretIndex + 1;
            }
            else if( rejectInputOnFirstFailure )
            {
              return false;
            }
              }

              if( ( selectionLength > 0 ) && ( startPosition <= endPosition ) )
              {

            // Erase the remaining of the assigned edit character.
            int notUsed;
            MaskedTextResultHint notUsedHint;
            if( !provider.RemoveAt( startPosition, endPosition, out notUsed, out notUsedHint ) )
              success = false;
              }

              return success;
        }
開發者ID:eolandezhang,項目名稱:Diagram,代碼行數:47,代碼來源:MaskedTextBox.cs


注:本文中的System.ComponentModel.MaskedTextProvider.FindEditPositionFrom方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。