Class TextPosition
Represents the TextPosition class.
Inheritance
Namespace: Syncfusion.Windows.Controls.RichTextBoxAdv
Assembly: Syncfusion.SfRichTextBoxAdv.WPF.dll
Syntax
public class TextPosition : Object
Constructors
TextPosition()
Initializes a new instance of the TextPosition class.
Declaration
public TextPosition()
Properties
GetHierarchicalIndex
Gets the hierarchical index of the TextPosition.
Declaration
public string GetHierarchicalIndex { get; }
Property Value
Type | Description |
---|---|
System.String | The hierarchical index of the TextPosition. |
HierarchicalIndex
Gets the hierarchical index of the TextPosition.
Declaration
public string HierarchicalIndex { get; }
Property Value
Type | Description |
---|---|
System.String | The hierarchical index of the TextPosition. |
Examples
The following code example demonstrates how to gets the hierarchical index of the TextPosition.
// Stores the logical position of selection start as static string.
string startHierarchicalIndex = richTextBoxAdv.Selection.Start.HierarchicalIndex;
// Gets the logical text position at specified index.
TextPosition position = richTextBoxAdv.Document.GetTextPosition(startHierarchicalIndex);
' Stores the logical position of selection start as static string.
Private startHierarchicalIndex As String = richTextBoxAdv.Selection.Start.HierarchicalIndex
' Gets the logical text position at specified index.
Private position As TextPosition = richTextBoxAdv.Document.GetTextPosition(startHierarchicalIndex)
Paragraph
Gets the ParagraphAdv at which the TextPosition lies.
Declaration
public ParagraphAdv Paragraph { get; }
Property Value
Type | Description |
---|---|
ParagraphAdv | The ParagraphAdv at which the TextPosition lies. |
Methods
GetRect()
Returns a bounding box System.Windows.Rect of the current TextPosition instance relative to SfRichTextBoxAdv control.
Declaration
public Rect GetRect()
Returns
Type | Description |
---|---|
System.Windows.Rect | The bounding box System.Windows.Rect. |
Examples
// Initializes a new instance of RichTextBoxAdv.
SfRichTextBoxAdv richTextBoxAdv = new SfRichTextBoxAdv();
// Gets the caret bounding box of Selection end.
Rect boundingRect = richTextBoxAdv.Selection.End.GetRect();
' Initializes a new instance of RichTextBoxAdv.
Dim richTextBoxAdv As New SfRichTextBoxAdv()
' Gets the caret bounding box of Selection end.
Dim boundingRect As Rect = richTextBoxAdv.Selection.End.GetRect()
IsAtSamePosition(TextPosition)
Identifies whether the specified TextPosition denotes the same position as this TextPosition.
Declaration
public bool IsAtSamePosition(TextPosition textPosition)
Parameters
Type | Name | Description |
---|---|---|
TextPosition | textPosition | A TextPosition instance that denotes a position to compare to this TextPosition instance. |
Returns
Type | Description |
---|---|
System.Boolean | True, if this TextPosition instance and the specified TextPosition both denotes the same position. Otherwise False. |
Examples
The following code example demonstrates how to identify whether two text positions denotes the same position.
<RichTextBoxAdv:SfRichTextBoxAdv x:Name="richTextBoxAdv"/>
public bool IsAtSamePosition()
{
TextPosition position1 = richTextBoxAdv.Document.GetTextPosition("0;0;0");
ParagraphAdv paragraph = richTextBoxAdv.Document.Sections[0].Blocks[0] as ParagraphAdv;
TextPosition position2 = richTextBoxAdv.Document.GetTextPosition(paragraph, 0);
if (position1.IsAtSamePosition(position2))
return true;
return false;
}
Public Function IsAtSamePosition() As Boolean
Dim position1 As TextPosition = richTextBoxAdv.Document.GetTextPosition("0;0;0")
Dim paragraph As ParagraphAdv = TryCast(richTextBoxAdv.Document.Sections(0).Blocks(0), ParagraphAdv)
Dim position2 As TextPosition = richTextBoxAdv.Document.GetTextPosition(paragraph, 0)
If position1.IsAtSamePosition(position2) Then
Return True
End If
Return False
End Function
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | The textPosition cannot be null. |
IsInSameDocument(TextPosition)
Identifies whether the specified see cref="TextPosition"/> lies in the same document as this TextPosition.
Declaration
public bool IsInSameDocument(TextPosition textPosition)
Parameters
Type | Name | Description |
---|---|---|
TextPosition | textPosition | A TextPosition instance that denotes a position to compare to this TextPosition instance. |
Returns
Type | Description |
---|---|
System.Boolean | True, if this TextPosition instance and the specified TextPosition both lies in the same document. Otherwise False. |
Examples
The following code example demonstrates how to identify whether two text positions lies in the same document.
<RichTextBoxAdv:SfRichTextBoxAdv x:Name="richTextBoxAdv"/>
public bool IsInSameDocument()
{
TextPosition position1 = richTextBoxAdv.Document.GetTextPosition("0;4;2");
ParagraphAdv paragraph = richTextBoxAdv.Document.Sections[0].Blocks[0] as ParagraphAdv;
TextPosition position2 = richTextBoxAdv.Document.GetTextPosition(paragraph, 0);
if (position1.IsInSameDocument(position2))
return true;
return false;
}
Public Function IsInSameDocument() As Boolean
Dim position1 As TextPosition = richTextBoxAdv.Document.GetTextPosition("0;4;2")
Dim paragraph As ParagraphAdv = TryCast(richTextBoxAdv.Document.Sections(0).Blocks(0), ParagraphAdv)
Dim position2 As TextPosition = richTextBoxAdv.Document.GetTextPosition(paragraph, 0)
If position1.IsInSameDocument(position2) Then
Return True
End If
Return False
End Function
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | The textPosition cannot be null. |
MoveToLineEnd()
Moves the TextPosition to the end of the line.
Declaration
public void MoveToLineEnd()
Examples
The following code example demonstrates how to select a line by moving the text position to the end of the line.
<RichTextBoxAdv:SfRichTextBoxAdv x:Name="richTextBoxAdv"/>
public void SelectLine()
{
// Retrieves the text position at the specified hierarchical position.
TextPosition startTextPosition = richTextBoxAdv.Document.GetTextPosition("0;3;16");
if (startTextPosition == null)
return;
// Moves the text position to the beginning of the line.
startTextPosition.MoveToLineStart();
// Initialize a new text position and moves it to the end of the line.
TextPosition endTextPosition = richTextBoxAdv.Document.GetTextPosition(startTextPosition.GetHierarchicalIndex);
endTextPosition.MoveToLineEnd();
// Selects the line.
richTextBoxAdv.Selection.Select(startTextPosition, endTextPosition);
}
Public Sub SelectLine()
' Retrieves the text position at the specified hierarchical position.
Dim startTextPosition As TextPosition = richTextBoxAdv.Document.GetTextPosition("0;3;16")
If startTextPosition Is Nothing Then
Return
End If
' Moves the text position to the beginning of the line.
startTextPosition.MoveToLineStart()
' Initialize a new text position and moves it to the end of the line.
Dim endTextPosition As TextPosition = richTextBoxAdv.Document.GetTextPosition(startTextPosition.GetHierarchicalIndex)
endTextPosition.MoveToLineEnd()
' Selects the line.
richTextBoxAdv.Selection.[Select](startTextPosition, endTextPosition)
End Sub
MoveToLineStart()
Moves the TextPosition to the beginning of the line.
Declaration
public void MoveToLineStart()
Examples
The following code example demonstrates how to select a line by moving the text position to the beginning of the line.
<RichTextBoxAdv:SfRichTextBoxAdv x:Name="richTextBoxAdv"/>
public void SelectLine()
{
// Retrieves the text position at the specified hierarchical position.
TextPosition startTextPosition = richTextBoxAdv.Document.GetTextPosition("0;3;16");
if (startTextPosition == null)
return;
// Moves the text position to the beginning of the line.
startTextPosition.MoveToLineStart();
// Initialize a new text position and moves it to the end of the line.
TextPosition endTextPosition = richTextBoxAdv.Document.GetTextPosition(startTextPosition.GetHierarchicalIndex);
endTextPosition.MoveToLineEnd();
// Selects the line.
richTextBoxAdv.Selection.Select(startTextPosition, endTextPosition);
}
Public Sub SelectLine()
' Retrieves the text position at the specified hierarchical position.
Dim startTextPosition As TextPosition = richTextBoxAdv.Document.GetTextPosition("0;3;16")
If startTextPosition Is Nothing Then
Return
End If
' Moves the text position to the beginning of the line.
startTextPosition.MoveToLineStart()
' Initialize a new text position and moves it to the end of the line.
Dim endTextPosition As TextPosition = richTextBoxAdv.Document.GetTextPosition(startTextPosition.GetHierarchicalIndex)
endTextPosition.MoveToLineEnd()
' Selects the line.
richTextBoxAdv.Selection.[Select](startTextPosition, endTextPosition)
End Sub
MoveToNextParagraphStart()
Moves the TextPosition to the beginning of the next paragraph.
Declaration
public void MoveToNextParagraphStart()
Examples
The following code example demonstrates how to select next paragraph by moving the text position to the beginning of the next paragraph.
<RichTextBoxAdv:SfRichTextBoxAdv x:Name="richTextBoxAdv"/>
public void SelectNextParagraph()
{
// Retrieves the text position at the specified hierarchical position.
TextPosition startTextPosition = richTextBoxAdv.Document.GetTextPosition("0;4;21");
if (startTextPosition == null)
return;
// Moves the text position to the beginning of the next paragraph.
startTextPosition.MoveToNextParagraphStart();
// Initialize a new text position and moves it to the end of the next paragraph.
TextPosition endTextPosition = richTextBoxAdv.Document.GetTextPosition(startTextPosition.GetHierarchicalIndex);
endTextPosition.MoveToParagraphEnd();
// Selects the next paragraph.
richTextBoxAdv.Selection.Select(startTextPosition, endTextPosition);
}
Public Sub SelectNextParagraph()
' Retrieves the text position at the specified hierarchical position.
Dim startTextPosition As TextPosition = richTextBoxAdv.Document.GetTextPosition("0;4;21")
If startTextPosition Is Nothing Then
Return
End If
' Moves the text position to the beginning of the next paragraph.
startTextPosition.MoveToNextParagraphStart()
' Initialize a new text position and moves it to the end of the next paragraph.
Dim endTextPosition As TextPosition = richTextBoxAdv.Document.GetTextPosition(startTextPosition.GetHierarchicalIndex)
endTextPosition.MoveToParagraphEnd()
' Selects the next paragraph.
richTextBoxAdv.Selection.[Select](startTextPosition, endTextPosition)
End Sub
MoveToParagraphEnd()
Moves the TextPosition to the end of the paragraph.
Declaration
public void MoveToParagraphEnd()
Examples
The following code example demonstrates how to select a paragraph move the text position to the end of the paragraph.
<RichTextBoxAdv:SfRichTextBoxAdv x:Name="richTextBoxAdv"/>
public void SelectParagraph()
{
// Retrieves the text position at the specified hierarchical position.
TextPosition startTextPosition = richTextBoxAdv.Document.GetTextPosition("0;2;16");
if (startTextPosition == null)
return;
// Moves the text position to the beginning of the paragraph.
startTextPosition.MoveToParagraphStart();
// Initialize a new text position and moves it to the end of the paragraph.
TextPosition endTextPosition = richTextBoxAdv.Document.GetTextPosition(startTextPosition.GetHierarchicalIndex);
endTextPosition.MoveToParagraphEnd();
// Selects the paragraph.
richTextBoxAdv.Selection.Select(startTextPosition, endTextPosition);
}
Public Sub SelectParagraph()
' Retrieves the text position at the specified hierarchical position.
Dim startTextPosition As TextPosition = richTextBoxAdv.Document.GetTextPosition("0;2;16")
If startTextPosition Is Nothing Then
Return
End If
' Moves the text position to the beginning of the paragraph.
startTextPosition.MoveToParagraphStart()
' Initialize a new text position and moves it to the end of the paragraph.
Dim endTextPosition As TextPosition = richTextBoxAdv.Document.GetTextPosition(startTextPosition.GetHierarchicalIndex)
endTextPosition.MoveToParagraphEnd()
' Selects the paragraph.
richTextBoxAdv.Selection.[Select](startTextPosition, endTextPosition)
End Sub
MoveToParagraphStart()
Moves the TextPosition to the beginning of the paragraph.
Declaration
public void MoveToParagraphStart()
Examples
The following code example demonstrates how to select a paragraph by moving the text position to the beginning of the paragraph.
<RichTextBoxAdv:SfRichTextBoxAdv x:Name="richTextBoxAdv"/>
public void SelectParagraph()
{
// Retrieves the text position at the specified hierarchical position.
TextPosition startTextPosition = richTextBoxAdv.Document.GetTextPosition("0;2;16");
if (startTextPosition == null)
return;
// Moves the text position to the beginning of the paragraph.
startTextPosition.MoveToParagraphStart();
// Initialize a new text position and moves it to the end of the paragraph.
TextPosition endTextPosition = richTextBoxAdv.Document.GetTextPosition(startTextPosition.GetHierarchicalIndex);
endTextPosition.MoveToParagraphEnd();
// Selects the paragraph.
richTextBoxAdv.Selection.Select(startTextPosition, endTextPosition);
}
Public Sub SelectParagraph()
' Retrieves the text position at the specified hierarchical position.
Dim startTextPosition As TextPosition = richTextBoxAdv.Document.GetTextPosition("0;2;16")
If startTextPosition Is Nothing Then
Return
End If
' Moves the text position to the beginning of the paragraph.
startTextPosition.MoveToParagraphStart()
' Initialize a new text position and moves it to the end of the paragraph.
Dim endTextPosition As TextPosition = richTextBoxAdv.Document.GetTextPosition(startTextPosition.GetHierarchicalIndex)
endTextPosition.MoveToParagraphEnd()
' Selects the paragraph.
richTextBoxAdv.Selection.[Select](startTextPosition, endTextPosition)
End Sub
MoveToPreviousParagraphEnd()
Moves the TextPosition to the end of the previous paragraph.
Declaration
public void MoveToPreviousParagraphEnd()
Examples
The following code example demonstrates how to select previous paragraph by moving the text position to the end of the previous paragraph.
<RichTextBoxAdv:SfRichTextBoxAdv x:Name="richTextBoxAdv"/>
public void SelectPreviousParagraph()
{
// Retrieves the text position at the specified hierarchical position.
TextPosition endTextPosition = richTextBoxAdv.Document.GetTextPosition("0;2;40");
if (endTextPosition == null)
return;
// Moves the text position to the end of the previous paragraph.
endTextPosition.MoveToPreviousParagraphEnd();
// Initialize a new text position and moves it to the beginning of the previous paragraph.
TextPosition startTextPosition = richTextBoxAdv.Document.GetTextPosition(endTextPosition.GetHierarchicalIndex);
startTextPosition.MoveToParagraphStart();
// Selects the previous paragraph.
richTextBoxAdv.Selection.Select(startTextPosition, endTextPosition);
}
Public Sub SelectPreviousParagraph()
' Retrieves the text position at the specified hierarchical position.
Dim endTextPosition As TextPosition = richTextBoxAdv.Document.GetTextPosition("0;2;40")
If endTextPosition Is Nothing Then
Return
End If
' Moves the text position to the end of the previous paragraph.
endTextPosition.MoveToPreviousParagraphEnd()
' Initialize a new text position and moves it to the start of the previous paragraph.
Dim startTextPosition As TextPosition = richTextBoxAdv.Document.GetTextPosition(endTextPosition.GetHierarchicalIndex)
startTextPosition.MoveToParagraphStart()
' Selects the previous paragraph.
richTextBoxAdv.Selection.[Select](startTextPosition, endTextPosition)
End Sub
MoveToWordEnd()
Moves the TextPosition to the end of word.
Declaration
public void MoveToWordEnd()
Examples
The following code example demonstrates how to select a word by moving the text position to the end of word.
<RichTextBoxAdv:SfRichTextBoxAdv x:Name="richTextBoxAdv"/>
public void SelectWord()
{
// Retrieves the text position at the specified hierarchical position.
TextPosition startTextPosition = richTextBoxAdv.Document.GetTextPosition("0;0;24");
if (startTextPosition == null)
return;
// Moves the text position to the beginning of the word.
startTextPosition.MoveToWordStart();
// Initialize a new text position and moves it to the end of the word.
TextPosition endTextPosition = richTextBoxAdv.Document.GetTextPosition(startTextPosition.GetHierarchicalIndex);
endTextPosition.MoveToWordEnd();
// Selects the word.
richTextBoxAdv.Selection.Select(startTextPosition, endTextPosition);
}
Public Sub SelectWord()
' Retrieves the text position at the specified hierarchical position.
Dim startTextPosition As TextPosition = richTextBoxAdv.Document.GetTextPosition("0;0;24")
If startTextPosition Is Nothing Then
Return
End If
' Moves the text position to the beginning of the word.
startTextPosition.MoveToWordStart()
' Initialize a new text position and moves it to the end of the word.
Dim endTextPosition As TextPosition = richTextBoxAdv.Document.GetTextPosition(startTextPosition.GetHierarchicalIndex)
endTextPosition.MoveToWordEnd()
' Selects the word.
richTextBoxAdv.Selection.[Select](startTextPosition, endTextPosition)
End Sub
MoveToWordStart()
Moves the TextPosition to the beginning of word.
Declaration
public void MoveToWordStart()
Examples
The following code example demonstrates how to select a word by moving the text position to the beginning of word.
<RichTextBoxAdv:SfRichTextBoxAdv x:Name="richTextBoxAdv"/>
public void SelectWord()
{
// Retrieves the text position at the specified hierarchical position.
TextPosition startTextPosition = richTextBoxAdv.Document.GetTextPosition("0;0;24");
if (startTextPosition == null)
return;
// Moves the text position to the beginning of the word.
startTextPosition.MoveToWordStart();
// Initialize a new text position and moves it to the end of the word.
TextPosition endTextPosition = richTextBoxAdv.Document.GetTextPosition(startTextPosition.GetHierarchicalIndex);
endTextPosition.MoveToWordEnd();
// Selects the word.
richTextBoxAdv.Selection.Select(startTextPosition, endTextPosition);
}
Public Sub SelectWord()
' Retrieves the text position at the specified hierarchical position.
Dim startTextPosition As TextPosition = richTextBoxAdv.Document.GetTextPosition("0;0;24")
If startTextPosition Is Nothing Then
Return
End If
' Moves the text position to the beginning of the word.
startTextPosition.MoveToWordStart()
' Initialize a new text position and moves it to the end of the word.
Dim endTextPosition As TextPosition = richTextBoxAdv.Document.GetTextPosition(startTextPosition.GetHierarchicalIndex)
endTextPosition.MoveToWordEnd()
' Selects the word.
richTextBoxAdv.Selection.[Select](startTextPosition, endTextPosition)
End Sub