RootNode.GetNodesFromTextRange 方法 (Int32%, Int32%)

返回后代 ContextNode 对象的集合,这些对象与已识别字符串中的指定文本范围相关。

命名空间:  Microsoft.Ink
程序集:  Microsoft.Ink.Analysis(在 Microsoft.Ink.Analysis.dll 中)

语法

声明
Public Function GetNodesFromTextRange ( _
    ByRef start As Integer, _
    ByRef length As Integer _
) As ContextNodeCollection
用法
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 ContextNodeCollection GetNodesFromTextRange(
    /** @ref */int start,
    /** @ref */int length
)
public function GetNodesFromTextRange(
    start : int, 
    length : int
) : ContextNodeCollection

参数

  • start
    类型:System.Int32%
    已识别字符串中文本范围的起点。
  • length
    类型:System.Int32%
    已识别字符串中文本范围的长度。

返回值

类型:Microsoft.Ink.ContextNodeCollection
后代 ContextNode 对象的集合,这些对象与已识别字符串中的指定文本范围相关。

备注

start 和 length 参数的值可以更改,因此属于引用参数。例如,GetRecognizedString 的返回值是“I am late”,并且传入的值为 start = 6 和 length = 1(对应于字母“a”)。那么 ContextNodeCollection 可能只有一个 ContextNode,即对应于单词“late”的 InkWordNode。在这种情况下,start 的值更改为 5,而 length 的值更改为 4,从而对应于整个单词“late”。

示例

下面的示例使用 TextBox (theResultsTextBox),其 Text 属性事先设置为由 GetRecognizedStringInkAnalyzer (theInkAnalyzer) 的 RootNode 返回的值。用户已经选择了 TextBox 中的部分文本,示例代码使用所选内容并标记与所选内容对应的 Strokes

Dim theRootNode As RootNode = DirectCast(theInkAnalyzer.RootNode, RootNode)
' Find out what's been selected in the text box
Dim selStart As Integer = theResultsTextBox.SelectionStart
Dim selLength As Integer = theResultsTextBox.SelectionLength

' Return if no text is selected.
' selLength must be > 0 or GetNodesFromTextRange(...) 
' will throw an ArgumentOutOfRangeException
If 0 = selLength 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

' First, set all strokes to black
Dim inkStroke As Stroke
For Each inkStroke In theRootNode.Strokes
    inkStroke.DrawingAttributes = New DrawingAttributes(Color.Black)
Next inkStroke
' Next, set all selected sub nodes to red
Dim node As ContextNode
For Each node In selectedSubNodes
    For Each inkStroke In node.Strokes
        inkStroke.DrawingAttributes = New DrawingAttributes(Color.Red)
    Next inkStroke
Next node
            RootNode theRootNode = (RootNode)theInkAnalyzer.RootNode;
            // Find out what's been selected in the text box
            int selStart = theResultsTextBox.SelectionStart;
            int selLength = theResultsTextBox.SelectionLength;


            // Return if no text is selected.
            // selLength must be > 0 or GetNodesFromTextRange(...) 
            // will throw an ArgumentOutOfRangeException
            if (0 == selLength)
            {
                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;

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

平台

Windows Vista

.NET Framework 和 .NET Compact Framework 并不是对每个平台的所有版本都提供支持。有关支持的版本的列表,请参见.NET Framework 系统要求

版本信息

.NET Framework

受以下版本支持:3.0

另请参见

参考

RootNode 类

RootNode 成员

GetNodesFromTextRange 重载

Microsoft.Ink 命名空间