次の方法で共有


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" で、文字 "a" に対応する値 start = 6 および length = 1 を渡した場合、ContextNodeCollectionContextNode は 1 つのみとなる可能性が高くなります ("late" という語に対応する InkWordNode)。この場合、start の値は 5 に、length の値は 4 に変更されます ("late" という語全体に対応)。

次の例では、TextBox、theResultsTextBox を使用します。この Text プロパティは、既に InkAnalyzer、theInkAnalyzer の RootNodeGetRecognizedString によって返された値に設定されています。ユーザーは、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 名前空間