Sdílet prostřednictvím


WritingRegionNode.GetTextRangeFromNodes Method

Given a collection of ContextNode objects, this method finds the corresponding text range in the recognized string.

Namespace:  System.Windows.Ink
Assembly:  IAWinFX (in IAWinFX.dll)

Syntax

'Declaration
Public Sub GetTextRangeFromNodes ( _
    subTree As ContextNodeCollection, _
    <OutAttribute> ByRef start As Integer, _
    <OutAttribute> ByRef length As Integer _
)
'Usage
Dim instance As WritingRegionNode 
Dim subTree As ContextNodeCollection 
Dim start As Integer 
Dim length As Integer

instance.GetTextRangeFromNodes(subTree, _
    start, length)
public void GetTextRangeFromNodes(
    ContextNodeCollection subTree,
    out int start,
    out int length
)
public:
void GetTextRangeFromNodes(
    ContextNodeCollection^ subTree, 
    [OutAttribute] int% start, 
    [OutAttribute] int% length
)
public function GetTextRangeFromNodes(
    subTree : ContextNodeCollection, 
    start : int, 
    length : int
)

Parameters

Remarks

If the subTree contains a ContextNode that is not a descendant of the InkWritingNode, an ArgumentException is thrown.

If the subTree contains ContextNode objects that are not consecutive, the smallest text range covering all of the ContextNode objects is returned.

Examples

The following example finds the last paragraph in a WritingRegionNode named writingRegion. It then finds the text range that corresponds to this paragraph, puts the value of GetRecognizedString into a TextBox named selectedResultsTextBox, and selects the text that corresponds to the last paragraph.

Dim paragraphs As ContextNodeCollection = theInkAnalyzer.FindNodesOfType(ContextNodeType.Paragraph)
Dim lastParagraph As ParagraphNode = Nothing 
Dim maxY As Double = Double.MinValue
Dim paragraph As ParagraphNode
For Each paragraph In  paragraphs
    If paragraph.Location.GetBounds().Bottom > maxY Then
        maxY = paragraph.Location.GetBounds().Bottom
        lastParagraph = paragraph
    End If 
Next paragraph

If lastParagraph Is Nothing Then 
    Return 
End If  
' Create a collection to hold this line 
Dim lastParagraphCollection As New ContextNodeCollection(theInkAnalyzer)
lastParagraphCollection.Add(lastParagraph)

' Find corresponding start and length 
Dim start, length As Integer
writingRegion.GetTextRangeFromNodes(lastParagraphCollection, start, length)

' Select this in the text box
selectedResultsTextBox.Text = writingRegion.GetRecognizedString()
selectedResultsTextBox.Select(start, length)
ContextNodeCollection paragraphs =
     theInkAnalyzer.FindNodesOfType(ContextNodeType.Paragraph);
ParagraphNode lastParagraph = null;
double maxY = double.MinValue;
foreach (ParagraphNode paragraph in paragraphs)
{
    if (paragraph.Location.GetBounds().Bottom > maxY)
    {
        maxY = paragraph.Location.GetBounds().Bottom;
        lastParagraph = paragraph;
    }
}

if (lastParagraph == null)
    return;

// Create a collection to hold this line
ContextNodeCollection lastParagraphCollection = new ContextNodeCollection(theInkAnalyzer);
lastParagraphCollection.Add(lastParagraph);

// Find corresponding start and length 
int start, length;
writingRegion.GetTextRangeFromNodes(lastParagraphCollection, out start, out length);

// Select this in the text box
selectedResultsTextBox.Text = writingRegion.GetRecognizedString();
selectedResultsTextBox.Select(start, length);

Platforms

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Version Information

.NET Framework

Supported in: 3.0

See Also

Reference

WritingRegionNode Class

WritingRegionNode Members

System.Windows.Ink Namespace