Compartir a través de


InkAnalyzer.GetTextRangeFromNodes Method

Finds the text range in the recognized string that corresponds to a collection of ContextNode objects.

Namespace: Microsoft.Ink
Assembly: Microsoft.Ink.Analysis (in microsoft.ink.analysis.dll)

Syntax

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

instance.GetTextRangeFromNodes(nodesToSearch, start, length)
public void GetTextRangeFromNodes (
    ContextNodeCollection nodesToSearch,
    out int start,
    out int length
)
public:
void GetTextRangeFromNodes (
    ContextNodeCollection^ nodesToSearch, 
    [OutAttribute] int% start, 
    [OutAttribute] int% length
)
public void GetTextRangeFromNodes (
    ContextNodeCollection nodesToSearch, 
    /** @attribute OutAttribute() */ /** @ref */ int start, 
    /** @attribute OutAttribute() */ /** @ref */ int length
)
Not applicable.

Parameters

  • nodesToSearch
    The collection of ContextNode objects for which to find the text range.
  • start
    When this method returns, the start parameter contains a 32-bit signed integer that indicates the start of the text range. This parameter is passed uninitialized.
  • length
    When this method returns, the length parameter contains a 32-bit signed integer that indicates the length of the text range. This parameter is passed uninitialized.

Remarks

If nodesToSearch contains ContextNode objects that are not adjacent, this method returns the smallest text range that covers all of the ContextNode objects.

This method throws a System.ArgumentException when nodesToSearch contains a ContextNode that is not associated with the InkAnalyzer.

Example

This example defines a method, SelectTextRangeFromNodes, that sets the text of the System.Windows.Forms.TextBox, theResultsTextBox, to the recognition string of the InkAnalyzer, theInkAnalyzer. It then sets the text box selection to span the recognized text for the parameter, theContextNodes.

''' <summary>
''' Selects the text range in the TextBox, theResultsTextBox, that represents
''' the node ranges in theContextNodes.
''' </summary>
''' <param name="theContextNodes">
''' The nodes for which to select the text range.</param>
''' <remarks>
''' If <paramref name="theContextNodes"/> are not current context nodes
''' of the InkAnalyzer, theInkAnalyzer, then GetTextRangeFromNodes throws
''' an ArgumentException.
''' </remarks>
Private Sub SelectTextRangeFromNodes(ByVal theContextNodes As Microsoft.Ink.ContextNodeCollection)
    ' Set the text of theResultsTextBox.
    Me.theResultsTextBox.Text = Me.theInkAnalyzer.GetRecognizedString()

    ' Get the text range for theContextNodes.
    Dim theStart As Integer
    Dim theLength As Integer
    Try
        Me.theInkAnalyzer.GetTextRangeFromNodes( _
            theContextNodes, theStart, theLength)
        ' Check for common exceptions.
    Catch ex As ArgumentException
        Throw New ArgumentException( _
            "Invalid ContextNodeCollection", "theContextNodes", ex)
    End Try

    ' Select the text range in the TextBox.
    Me.theResultsTextBox.Select(theStart, theLength)
    Me.theResultsTextBox.Invalidate()

End Sub 'SelectTextRangeFromNodes
/// <summary>
/// Selects the text range in the TextBox, theResultsTextBox, that represents
/// the node ranges in theContextNodes.
/// </summary>
/// <param name="theContextNodes">
/// The nodes for which to select the text range.</param>
/// <remarks>
/// If <paramref name="theContextNodes"/> are not current context nodes
/// of the InkAnalyzer, theInkAnalyzer, then GetTextRangeFromNodes throws
/// an ArgumentException.
/// </remarks>
private void SelectTextRangeFromNodes(
    Microsoft.Ink.ContextNodeCollection theContextNodes)
{
    // Set the text of theResultsTextBox.
    this.theResultsTextBox.Text = this.theInkAnalyzer.GetRecognizedString();

    // Get the text range for theContextNodes.
    int theStart;
    int theLength;
    try
    {
        this.theInkAnalyzer.GetTextRangeFromNodes(
            theContextNodes, out theStart, out theLength);
    }
    // Check for common exceptions.
    catch (ArgumentException ex)
    {
        throw new ArgumentException("Invalid ContextNodeCollection",
            "theContextNodes", ex);
    }

    // Select the text range in the TextBox.
    this.theResultsTextBox.Select(theStart, theLength);
    this.theResultsTextBox.Invalidate();
}

Platforms

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

Version Information

.NET Framework

Supported in: 3.0

See Also

Reference

InkAnalyzer Class
InkAnalyzer Members
Microsoft.Ink Namespace