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


C# ITextRange.Select方法代码示例

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


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

示例1: ApplyInitialTypingHeuristics

 // Apply initial typing heuristics -- adjust range for typing 
 // when it spans one or more TableCells.
 // 
 // ApplyInitialTypingHeuristics/ApplyFinalTypingHeuristics are
 // called together, with a an extra step in between for TextSelection
 // overrides of the ApplyTypingHueristic method.
 internal static void ApplyInitialTypingHeuristics(ITextRange thisRange) 
 {
     // When table cells selected, clear the start cell and collapse selection into it 
     if (thisRange.IsTableCellRange) 
     {
         TableCell cell; 
         if (thisRange.Start is TextPointer &&
             (cell = TextRangeEditTables.GetTableCellFromPosition((TextPointer)thisRange.Start)) != null)
         {
             // Select the first cell content to make springload formatting happen below 
             thisRange.Select(cell.ContentStart, cell.ContentEnd);
         } 
         else 
         {
             thisRange.Select(thisRange.Start, thisRange.Start); 
         }
     }
 }
开发者ID:sjyanxin,项目名称:WPFSource,代码行数:24,代码来源:TextRangeBase.cs

示例2: ApplyFinalTypingHeuristics

        // Apply typing heuristics
        //  - extend for overtype. 
        //  - prevent paragraph merges when only the leading edge of that 
        //    last paragraph is selected.
        // 
        // ApplyInitialTypingHeuristics/ApplyFinalTypingHeuristics are
        // called together, with a an extra step in between for TextSelection
        // overrides of the ApplyTypingHueristic method.
        internal static void ApplyFinalTypingHeuristics(ITextRange thisRange, bool overType) 
        {
            // Expand empty selection forward in overtype mode 
            if (overType && thisRange.IsEmpty && 
                !TextPointerBase.IsNextToAnyBreak(thisRange.End, LogicalDirection.Forward))
            { 
                //


                ITextPointer nextPosition = thisRange.End.CreatePointer(); 
                nextPosition.MoveToNextInsertionPosition(LogicalDirection.Forward);
                if (!TextRangeEditTables.IsTableStructureCrossed(thisRange.Start, nextPosition)) 
                { 
                    TextRange range = new TextRange(thisRange.Start, nextPosition);
                    Invariant.Assert(!range.IsTableCellRange); 

                    range.Text = String.Empty;
                }
            } 

            // If the range is non-empty, and its end just passes a paragraph break, 
            // pull the end back to stop a paragraph merge on the next keystroke. 
            if (!thisRange.IsEmpty &&
                (TextPointerBase.IsNextToAnyBreak(thisRange.End, LogicalDirection.Backward) || 
                 TextPointerBase.IsAfterLastParagraph(thisRange.End)))
            {
                ITextPointer newEnd = thisRange.End.GetNextInsertionPosition(LogicalDirection.Backward);
                thisRange.Select(thisRange.Start, newEnd); 
            }
        } 
开发者ID:sjyanxin,项目名称:WPFSource,代码行数:38,代码来源:TextRangeBase.cs

示例3: SetText

        // Implementation of a setter fot ITextRange.Text property
        internal static void SetText(ITextRange thisRange, string textData) 
        {
            NormalizeRange(thisRange); 
 
            if (textData == null)
            { 
                throw new ArgumentNullException("textData");
            }

            ITextPointer explicitInsertPosition = null; 

            TextRangeBase.BeginChange(thisRange); 
            try 
            {
                // Delete content covered by this range 
                if (!thisRange.IsEmpty)
                {
                    if (thisRange.Start is TextPointer &&
                        ((TextPointer)thisRange.Start).Parent == ((TextPointer)thisRange.End).Parent && 
                        ((TextPointer)thisRange.Start).Parent is Run &&
                        textData.Length > 0) 
                    { 
                        // When textrange start/end are parented by the same Run, we can optimize
                        // and delete content without any checks. 
                        //
                        // Note that NOT doing so has a serious side effect in this case.
                        // Low-level code in TextRangeEdit does not preserve an empty run
                        // with no formatting properties after deletion. 
                        // We dont want to loose the empty Run,
                        // when we are just about to set the range text to non-empty string. 
                        // Otherwise, newly inserted text might have undesirable formatting properties 
                        // applied due to an insertion position within an adjacent Run.
 
                        if (thisRange.Start.GetPointerContext(LogicalDirection.Backward) == TextPointerContext.Text &&
                            thisRange.End.GetPointerContext(LogicalDirection.Forward) == TextPointerContext.Text)
                        {
                            // If we're deleting with surrounding text, make sure we insert later between the surrounding text. 
                            // Because we will invalidate layout with the delete, it's possible that thisRange.Start
                            // will normalize itself to a different character offset on the next reference. 
                            // This is because -- unfortunately -- when layout is valid we use ITextView.IsAtCaretUnitBoundary 
                            // to normalize unicode offsets, but when layout is dirty we use a different code path
                            // that ignores the current font and simply checks Unicode values for surrogates and 
                            // combining marks.  See bug 1683515 for an example.
                            explicitInsertPosition = thisRange.Start;
                        }
 
                        TextContainer textContainer = ((TextPointer)thisRange.Start).TextContainer;
                        textContainer.DeleteContentInternal((TextPointer)thisRange.Start, (TextPointer)thisRange.End); 
                    } 
                    else
                    { 
                        thisRange.Start.DeleteContentToPosition(thisRange.End);
                    }

                    if (thisRange.Start is TextPointer) 
                    {
                        TextRangeEdit.MergeFlowDirection((TextPointer)thisRange.Start); 
                    } 

                    thisRange.Select(thisRange.Start, thisRange.Start); 
                }

                // Insert text at end position
                // Note that the non-emptiness check below is not an optimization: 
                // In case of empty text the code block in it would change an empty range
                // orientation, which is undesirable side effect. 
                // Also if the inserted text is empty we need to avoid ensuring insertion position, 
                // which can create paragraphs etc.
                if (textData.Length > 0) 
                {
                    ITextPointer insertPosition = (explicitInsertPosition == null) ? thisRange.Start : explicitInsertPosition;

                    // Ensure last paragraph existence and prepare ends for the new selection 
                    bool pastedFragmentEndsWithNewLine = textData.EndsWith("\n", StringComparison.Ordinal);
 
                    // We are going to insert paragraph implicitly when the block content becomes totally empty. 
                    // Store the fact that implicit paragraph was inserted to exclude ane extra paragraph break
                    // from the end of pasted fragment 
                    bool implicitParagraphInserted = insertPosition is TextPointer &&
                        TextSchema.IsValidChild(/*position*/insertPosition, /*childType*/typeof(Block)) &&
                        (insertPosition.GetPointerContext(LogicalDirection.Backward) == TextPointerContext.None ||
                        insertPosition.GetPointerContext(LogicalDirection.Backward) == TextPointerContext.ElementStart) && 
                        (insertPosition.GetPointerContext(LogicalDirection.Forward) == TextPointerContext.None ||
                        insertPosition.GetPointerContext(LogicalDirection.Forward) == TextPointerContext.ElementEnd); 
 
                    // Make sure that the range is positioned at insertion position
                    if (insertPosition is TextPointer && explicitInsertPosition == null) 
                    {
                        TextPointer insertionPosition = TextRangeEditTables.EnsureInsertionPosition((TextPointer)insertPosition);
                        thisRange.Select(insertionPosition, insertionPosition);
                        insertPosition = thisRange.Start; 
                    }
                    Invariant.Assert(TextSchema.IsInTextContent(insertPosition), "range.Start is expected to be in text content"); 
 
                    ITextPointer newStart = insertPosition.GetFrozenPointer(LogicalDirection.Backward);
                    ITextPointer newEnd = insertPosition.CreatePointer(LogicalDirection.Forward); 

                    if ((newStart is TextPointer) && ((TextPointer)newStart).Paragraph != null)
                    {
//.........这里部分代码省略.........
开发者ID:sjyanxin,项目名称:WPFSource,代码行数:101,代码来源:TextRangeBase.cs


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