Пример #1
0
        public static TextRange GetRangeIncludePointer(this TextPointer p, int leftLen, int rightLen)
        {
            TextPointer positionAtCharOffset  = p.GetPositionAtCharOffset(-1 * leftLen, LogicalDirection.Forward);
            TextPointer positionAtCharOffset2 = p.GetPositionAtCharOffset(rightLen, LogicalDirection.Backward);

            return(new TextRange(positionAtCharOffset, positionAtCharOffset2));
        }
Пример #2
0
 public static TextRange GetRange(this RichTextBox rtb, TextPointer p, int len)
 {
     try
     {
         if (p == null)
         {
             return(null);
         }
         TextPointer positionAtCharOffset;
         if (len >= 0)
         {
             p = p.GetPositionAtOffset(0, LogicalDirection.Forward);
             positionAtCharOffset = p.GetPositionAtCharOffset(len, LogicalDirection.Backward);
             return(new TextRange(p, positionAtCharOffset));
         }
         p = p.GetPositionAtOffset(0, LogicalDirection.Backward);
         positionAtCharOffset = p.GetPositionAtCharOffset(len, LogicalDirection.Forward);
         return(new TextRange(positionAtCharOffset, p));
     }
     catch
     {
     }
     return(null);
 }