Share via


RootNode.GetNodesFromTextRange Method (Int32%, Int32%)

Returns a collection of descendant ContextNode objects which pertain to the specified text range in the recognized string.

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

Syntax

'Declaration
Public Function GetNodesFromTextRange ( _
    ByRef start As Integer, _
    ByRef length As Integer _
) As ContextNodeCollection
'Usage
Dim instance As RootNode 
Dim start As Integer 
Dim length As Integer 
Dim returnValue As ContextNodeCollection 

returnValue = instance.GetNodesFromTextRange(start, _
    length)
public ContextNodeCollection GetNodesFromTextRange(
    ref int start,
    ref int length
)
public:
ContextNodeCollection^ GetNodesFromTextRange(
    int% start, 
    int% length
)
public function GetNodesFromTextRange(
    start : int, 
    length : int
) : ContextNodeCollection

Parameters

Return Value

Type: System.Windows.Ink.ContextNodeCollection
The collection of descendant ContextNode objects that are relevant to the specified text range in the recognized string.

Remarks

The start and length parameters are reference values that may be changed to specify an entire string associated with the returned ContextNodeCollection. For example, if the return value of GetRecognizedString is "I am late" and you pass in values of start = 6 and length = 1, thse parameters correspond to the letter "a." Therefore, the ContextNodeCollection is likely to contain just one ContextNode, namely, the InkWordNode corresponding to the word "late." In this example, the value of start is changed to 5 and the value of length is changed to 4 (corresponding to the entire word "late").

Examples

The following example uses the GetNodesFromTextRange method to mark strokes that correspond to selected text. The example code assumes that the Text property of the TextBox named theResultsTextBox, is set to the value returned by the GetRecognizedString method, and that the user has selected some text in theResultsTextBox. This example also assumes that there is an InkAnalyzer named theInkAnalyzer.

Dim theRootNode As RootNode = CType(theInkAnalyzer.RootNode, RootNode)

' First, set all strokes to black 
For Each stroke As Stroke In theRootNode.Strokes
    stroke.DrawingAttributes.Color = Colors.Black
Next stroke

' Find out what's been selected in the text box 
Dim selStart As Integer = theResultsTextBox.SelectionStart
Dim selLength As Integer = theResultsTextBox.SelectionLength

' Do nothing if no text is selected. 
If selLength = 0 Then 
    Return 
End If 

' Get the nodes that correspond to that range 
Dim selectedSubNodes As ContextNodeCollection = _
    theRootNode.GetNodesFromTextRange(selStart, selLength)

' Use the new start and length value to update the 
' selection in the TextBox
theResultsTextBox.SelectionStart = selStart
theResultsTextBox.SelectionLength = selLength

' Next, set all selected sub nodes to red 
Dim node As ContextNode
For Each node In  selectedSubNodes
    Dim stroke As Stroke
    For Each stroke In  node.Strokes
        stroke.DrawingAttributes.Color = Colors.Red
    Next stroke
Next node
RootNode theRootNode = (RootNode)theInkAnalyzer.RootNode;

// First, set all strokes to black 
foreach (Stroke stroke in theRootNode.Strokes)
    stroke.DrawingAttributes.Color = Colors.Black;

// Find out what's been selected in the text box 
int selStart = theResultsTextBox.SelectionStart;
int selLength = theResultsTextBox.SelectionLength;

// Do nothing if no text is selected. 
if (selLength == 0)
{
    return;
}
// Get the nodes that correspond to that range
ContextNodeCollection selectedSubNodes =
        theRootNode.GetNodesFromTextRange(ref selStart, ref selLength);


// Use the new start and length value to update the 
// selection in the TextBox
theResultsTextBox.SelectionStart = selStart;
theResultsTextBox.SelectionLength = selLength;

// Next, set all selected sub nodes to red 
foreach (ContextNode node in selectedSubNodes)
{
    foreach (Stroke stroke in node.Strokes)
    {
        stroke.DrawingAttributes.Color = Colors.Red;
    }
}

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

RootNode Class

RootNode Members

GetNodesFromTextRange Overload

System.Windows.Ink Namespace