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


C# TextLine.GetDistanceFromCharacterHit方法代码示例

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


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

示例1: GetTextLineVisualXPosition

 /// <summary>
 /// Gets the distance to the left border of the text area of the specified visual column.
 /// The visual column must belong to the specified text line.
 /// </summary>
 public double GetTextLineVisualXPosition(TextLine textLine, int visualColumn)
 {
     if (textLine == null)
         throw new ArgumentNullException("textLine");
     double xPos = textLine.GetDistanceFromCharacterHit(
         new CharacterHit(Math.Min(visualColumn, VisualLengthWithEndOfLineMarker), 0));
     if (visualColumn > VisualLengthWithEndOfLineMarker) {
         xPos += (visualColumn - VisualLengthWithEndOfLineMarker) * textView.WideSpaceWidth;
     }
     return xPos;
 }
开发者ID:eolandezhang,项目名称:Diagram,代码行数:15,代码来源:VisualLine.cs

示例2: FindSelectedArea

		private void FindSelectedArea(int idx, int txtLen, int txtOffset, double x, TextLine line, ref double start, ref double end)
		{
			int first = Math.Max(txtOffset, this.SelectionStart - idx);
			int last = Math.Min(txtLen - 1 + txtOffset, this.SelectionEnd - idx);
			if (last >= first)
			{
				start = Math.Min(start, line.GetDistanceFromCharacterHit(new CharacterHit(first, 0)) + x);
				end = Math.Max(end, line.GetDistanceFromCharacterHit(new CharacterHit(last, 1)) + x);
			}
		}
开发者ID:derrickcreamer,项目名称:Floe,代码行数:10,代码来源:ChatPresenter_Selecting.cs

示例3: MoveCaretUpDown

 static void MoveCaretUpDown(TextArea textArea, CaretMovementType direction, VisualLine visualLine, TextLine textLine, int caretVisualColumn)
 {
     // moving up/down happens using the desired visual X position
     double xPos = textArea.Caret.DesiredXPos;
     if (double.IsNaN(xPos))
         xPos = textLine.GetDistanceFromCharacterHit(new CharacterHit(caretVisualColumn, 0));
     // now find the TextLine+VisualLine where the caret will end up in
     VisualLine targetVisualLine = visualLine;
     TextLine targetLine;
     int textLineIndex = visualLine.TextLines.IndexOf(textLine);
     switch (direction) {
         case CaretMovementType.LineUp:
             {
                 // Move up: move to the previous TextLine in the same visual line
                 // or move to the last TextLine of the previous visual line
                 int prevLineNumber = visualLine.FirstDocumentLine.LineNumber - 1;
                 if (textLineIndex > 0) {
                     targetLine = visualLine.TextLines[textLineIndex - 1];
                 } else if (prevLineNumber >= 1) {
                     DocumentLine prevLine = textArea.Document.GetLineByNumber(prevLineNumber);
                     targetVisualLine = textArea.TextView.GetOrConstructVisualLine(prevLine);
                     targetLine = targetVisualLine.TextLines[targetVisualLine.TextLines.Count - 1];
                 } else {
                     targetLine = null;
                 }
                 break;
             }
         case CaretMovementType.LineDown:
             {
                 // Move down: move to the next TextLine in the same visual line
                 // or move to the first TextLine of the next visual line
                 int nextLineNumber = visualLine.LastDocumentLine.LineNumber + 1;
                 if (textLineIndex < visualLine.TextLines.Count - 1) {
                     targetLine = visualLine.TextLines[textLineIndex + 1];
                 } else if (nextLineNumber <= textArea.Document.LineCount) {
                     DocumentLine nextLine = textArea.Document.GetLineByNumber(nextLineNumber);
                     targetVisualLine = textArea.TextView.GetOrConstructVisualLine(nextLine);
                     targetLine = targetVisualLine.TextLines[0];
                 } else {
                     targetLine = null;
                 }
                 break;
             }
         case CaretMovementType.PageUp:
         case CaretMovementType.PageDown:
             {
                 // Page up/down: find the target line using its visual position
                 double yPos = visualLine.GetTextLineVisualYPosition(textLine, VisualYPosition.LineMiddle);
                 if (direction == CaretMovementType.PageUp)
                     yPos -= textArea.TextView.RenderSize.Height;
                 else
                     yPos += textArea.TextView.RenderSize.Height;
                 DocumentLine newLine = textArea.TextView.GetDocumentLineByVisualTop(yPos);
                 targetVisualLine = textArea.TextView.GetOrConstructVisualLine(newLine);
                 targetLine = targetVisualLine.GetTextLineByVisualYPosition(yPos);
                 break;
             }
         default:
             throw new NotSupportedException(direction.ToString());
     }
     if (targetLine != null) {
         CharacterHit ch = targetLine.GetCharacterHitFromDistance(xPos);
         SetCaretPosition(textArea, targetVisualLine, targetLine, ch, false);
         textArea.Caret.DesiredXPos = xPos;
     }
 }
开发者ID:Amichai,项目名称:PhysicsPad,代码行数:66,代码来源:CaretNavigationCommandHandler.cs

示例4: GetTextBoundsOnLine

		private List<textView.TextBounds> GetTextBoundsOnLine(TextLine textLine, Double horizontalOffset, Int32 startIndex, Int32 endIndex)
		{
			var list = new List<textView.TextBounds>();
			if (startIndex == endIndex)
			{
				Double distanceFromCharacterHit = textLine.GetDistanceFromCharacterHit(new CharacterHit(startIndex, 0));
				list.Add(new textView.TextBounds((distanceFromCharacterHit + horizontalOffset) + this.HorizontalOffset, this.VerticalOffset, 0, this.Height));
				return list;
			}
			foreach (textFormatting.TextBounds bounds in textLine.GetTextBounds(startIndex, endIndex - startIndex))
			{
				list.Add(new textView.TextBounds(bounds.Rectangle.Left + horizontalOffset, bounds.Rectangle.Top + this.VerticalOffset, bounds.Rectangle.Width, this.Height));
			}
			return list;
		}
开发者ID:xuchuansheng,项目名称:GenXSource,代码行数:15,代码来源:TextLineVisual.cs


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