本文整理汇总了C#中System.Windows.Documents.TextPointer.GetNextInsertionPosition方法的典型用法代码示例。如果您正苦于以下问题:C# TextPointer.GetNextInsertionPosition方法的具体用法?C# TextPointer.GetNextInsertionPosition怎么用?C# TextPointer.GetNextInsertionPosition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Documents.TextPointer
的用法示例。
在下文中一共展示了TextPointer.GetNextInsertionPosition方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RemoveHyperlink
public static TextPointer RemoveHyperlink(TextPointer start)
{
var backspacePosition = start.GetNextInsertionPosition(LogicalDirection.Backward);
Hyperlink hyperlink;
if (backspacePosition == null || !IsHyperlinkBoundaryCrossed(start, backspacePosition, out hyperlink))
{
return null;
}
// Remember caretPosition with forward gravity. This is necessary since we are going to delete
// the hyperlink element preceeding caretPosition and after deletion current caretPosition
// (with backward gravity) will follow content preceeding the hyperlink.
// We want to remember content following the hyperlink to set new caret position at.
var newCaretPosition = start.GetPositionAtOffset(0, LogicalDirection.Forward);
// Deleting the hyperlink is done using logic below.
// 1. Copy its children Inline to a temporary array.
var hyperlinkChildren = hyperlink.Inlines;
var inlines = new Inline[hyperlinkChildren.Count];
hyperlinkChildren.CopyTo(inlines, 0);
// 2. Remove each child from parent hyperlink element and insert it after the hyperlink.
for (int i = inlines.Length - 1; i >= 0; i--)
{
hyperlinkChildren.Remove(inlines[i]);
hyperlink.SiblingInlines.InsertAfter(hyperlink, inlines[i]);
}
// 3. Apply hyperlink's local formatting properties to inlines (which are now outside hyperlink scope).
var localProperties = hyperlink.GetLocalValueEnumerator();
var inlineRange = new TextRange(inlines[0].ContentStart, inlines[inlines.Length - 1].ContentEnd);
while (localProperties.MoveNext())
{
var property = localProperties.Current;
var dp = property.Property;
object value = property.Value;
if (!dp.ReadOnly &&
dp != Inline.TextDecorationsProperty && // Ignore hyperlink defaults.
dp != TextElement.ForegroundProperty &&
dp != BaseUriHelper.BaseUriProperty &&
!IsHyperlinkProperty(dp))
{
inlineRange.ApplyPropertyValue(dp, value);
}
}
// 4. Delete the (empty) hyperlink element.
hyperlink.SiblingInlines.Remove(hyperlink);
return newCaretPosition;
}
示例2: SetCell
public void SetCell(BufferCell cell, TextPointer position, LogicalDirection direction)
{
TextRange range = null;
TextPointer positionPlus = position.GetNextInsertionPosition(LogicalDirection.Forward);
if (positionPlus != null)
{
range = new TextRange(position, positionPlus);
}
if (null == range || range.IsEmpty)
{
position = position.GetInsertionPosition(LogicalDirection.Forward);
if (position != null)
{
Run r = position.GetAdjacentElement(LogicalDirection.Forward) as Run;
if (null != r)
{
if (r.Text.Length > 0)
{
char[] chr = r.Text.ToCharArray();
chr[0] = cell.Character;
r.Text = chr.ToString();
}
else
{
r.Text = cell.Character.ToString();
}
}
else
{
r = position.GetAdjacentElement(LogicalDirection.Backward) as Run;
if (null != r
&& r.Background == BrushFromConsoleColor(cell.BackgroundColor)
&& r.Foreground == BrushFromConsoleColor(cell.ForegroundColor)
)
{
if (r.Text.Length > 0)
{
r.Text = r.Text + cell.Character;
}
else
{
r.Text = cell.Character.ToString();
}
}
else
{
r = new Run(cell.Character.ToString(), position);
}
}
r.Background = BrushFromConsoleColor(cell.BackgroundColor);
r.Foreground = BrushFromConsoleColor(cell.ForegroundColor);
//position = r.ElementStart;
}
}
else
{
range.Text = cell.Character.ToString();
range.ApplyPropertyValue(TextElement.BackgroundProperty, BrushFromConsoleColor(cell.BackgroundColor));
range.ApplyPropertyValue(TextElement.ForegroundProperty, BrushFromConsoleColor(cell.ForegroundColor));
}
}
示例3: GetColumnNumberFromSelection
internal static int GetColumnNumberFromSelection(TextPointer position)
{
if (position == null)
{
return 0;
}
int linesMoved;
TextPointer lineStartPosition = position.GetLineStartPosition(0, out linesMoved);
int columnNumber = 0;
do
{
columnNumber++;
position = position.GetNextInsertionPosition(LogicalDirection.Backward);
}
while (position != null && position.CompareTo(lineStartPosition) > 0);
return columnNumber;
}
示例4: GetSentenceFromPosition
public static string GetSentenceFromPosition(RichTextBox rtb, TextPointer position)
{
string sentence = string.Empty;
while (true)
{
string c = GetCharacterAtPosition(rtb, position);
sentence += c;
if (c.Equals(".")) break;
position = position.GetNextInsertionPosition(LogicalDirection.Forward);
if (position == null) break;
}
return (sentence);
}