共用方式為


LineNode.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 LineNode
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 物件集合,這些物件都與已辨識字串中指定的文字範圍相關聯。

備註

指定的文字範圍應該相對於這個 LineNode 的已辨識字串,而不是整個 RootNode 的已辨識字串。

start 和 length 參數都是參考,因為它們的值可以變更。例如,GetRecognizedString 的傳回值為 "I am late",而且您傳入 start = 6 和 length = 1 兩個值 (表示對應於 "a" 這個字母),則 ContextNodeCollection 可能只有一個 ContextNode,這是對應於 "late" 一字的 InkWordNode。在此情況下,start 的值會變更為 5,而且 length 的值會變更為 4,表示對應於 "late" 這一整個字。

範例

下列範例會採用 TextBox (英文) (selectedResultsTextBox),它的 TextBox.Text (英文) 屬性先前已設定為 LineNode (line) 之 GetRecognizedString 所傳回的值。使用者已選取 TextBox (英文) 中的部分文字。這個範例程式碼會採用該選取範圍,並且將與其對應的 Strokes 加上標記。

' Find out what's been selected in the text box
Dim start As Integer = selectedResultsTextBox.SelectionStart
Dim length As Integer = selectedResultsTextBox.SelectionLength

' Return if no text is selected.
If start = 0 Then
    Return
End If

' Get the nodes that correspond to that range
Dim selectedNodes As ContextNodeCollection
selectedNodes = line.GetNodesFromTextRange(start, length)

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

' Color the strokes red if part of the selected words.
' Otherwise, color them black.
For Each node As ContextNode In line.SubNodes
    Dim inkStroke As Stroke
    For Each inkStroke In node.Strokes
        If selectedNodes.Contains(node) Then
            inkStroke.DrawingAttributes = New DrawingAttributes(Color.Red)
        Else
            inkStroke.DrawingAttributes = New DrawingAttributes(Color.Black)
        End If
    Next inkStroke
Next node
                    // Find out what's been selected in the text box
                    int start = selectedResultsTextBox.SelectionStart;
                    int length = selectedResultsTextBox.SelectionLength;

                    // Return if no text is selected.
                    if (length == 0)
                        return;

                    // Get the nodes that correspond to that range
                    ContextNodeCollection selectedNodes =
                        line.GetNodesFromTextRange(ref start, ref length);

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

                    // Color the strokes red if part of the selected words.
                    // Otherwise, color them black.
                    foreach (ContextNode node in line.SubNodes)
                    {
                        foreach (Stroke stroke in node.Strokes)
                        {
                            if (selectedNodes.Contains(node))
                            {
                                stroke.DrawingAttributes =
                                    new DrawingAttributes(Color.Red);
                            }
                            else
                            {
                                stroke.DrawingAttributes =
                                    new DrawingAttributes(Color.Black);
                            }
                        }
                    }

平台

Windows Vista

.NET Framework 和 .NET Compact Framework 並不支援各種平台的所有版本。如需支援平台版本的相關資訊,請參閱 .NET Framework 系統需求

版本資訊

.NET Framework

支援版本:3.0

請參閱

參考

LineNode 類別

LineNode 成員

GetNodesFromTextRange 多載

Microsoft.Ink 命名空間