共用方式為


InkAnalyzer.GetNodesFromTextRange 方法 (Int32%, Int32%, ContextNodeCollection)

傳回 ContextNode 物件的集合,這些物件與所指定內容節點的指定文字範圍相關聯。

命名空間:  Microsoft.Ink
組件:  Microsoft.Ink.Analysis (在 Microsoft.Ink.Analysis.dll 中)

語法

'宣告
Public Function GetNodesFromTextRange ( _
    ByRef start As Integer, _
    ByRef length As Integer, _
    nodesToSearch As ContextNodeCollection _
) As ContextNodeCollection
'用途
Dim instance As InkAnalyzer
Dim start As Integer
Dim length As Integer
Dim nodesToSearch As ContextNodeCollection
Dim returnValue As ContextNodeCollection

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

參數

  • start
    型別:System.Int32%
    已辨識字串的 nodesToSearch 部分中文字範圍開頭的參考。
  • length
    型別:System.Int32%
    已辨識字串的 nodesToSearch 部分中文字範圍長度的參考。

傳回值

型別:Microsoft.Ink.ContextNodeCollection
ContextNode 物件,與所指定內容節點的指定文字範圍相關。

備註

指定的文字範圍應該相對於 InkAnalyzer 中已辨識字串的 nodesToSearch 部分,而不是整個 InkAnalyzer 的已辨識字串。

這個方法會透過將文字範圍擴充至最接近的文字界限修改 start 和 length 參數的值。

例如,如果已辨識字串為 "I am late" 而且您針對 start 使用參數值 6 以及 length 使用參數值 1 呼叫這個方法,其對應至 "late" 中的字母 "a",則這個方法會傳回包含單一 ContextNodeInkWordNodeTextWordNode 且對應至 "late" 這個字的集合。在這個範例中,這個方法也會將 start 的值修改為 5 並將 length 的值修改為 4,這會對應於 "late" 一字。

ms569001.alert_note(zh-tw,VS.90).gif注意事項:

start 參數相對於 nodesToSearch 參數的已辨識字串。

範例

這個範例會採用 System.Windows.Forms.TextBox, theResultsTextBox,其 Text 屬性已設為 ContextNodeCollection (nodesToSearch) 的節點中組合的已辨識字串。nodesToSearch 集合包含來自 InkAnalyzer (theInkAnalyzer) 的內容節點。這個範例程式碼會採用文字方塊選取範圍,並且標記對應至該選取範圍的 Strokes

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

' Get the nodes that correspond to that range
Dim selectedSubNodes As Microsoft.Ink.ContextNodeCollection = _
    Me.theInkAnalyzer.GetNodesFromTextRange( _
        selStart, selLength, nodesToSearch)

' 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 theStroke As Microsoft.Ink.Stroke
For Each theStroke In Me.theInkAnalyzer.RootNode.Strokes
    theStroke.DrawingAttributes = _
        New Microsoft.Ink.DrawingAttributes(Color.Black)
Next theStroke

' Next, set all selected sub nodes to red
Dim theContextNode As Microsoft.Ink.ContextNode
For Each theContextNode In selectedSubNodes
    For Each theStroke In theContextNode.Strokes
        theStroke.DrawingAttributes = _
            New Microsoft.Ink.DrawingAttributes(Color.Red)
    Next theStroke
Next theContextNode
// Find out what's been selected in the text box
int selStart = theResultsTextBox.SelectionStart;
int selLength = theResultsTextBox.SelectionLength;

// Get the nodes that correspond to that range
Microsoft.Ink.ContextNodeCollection selectedSubNodes =
    this.theInkAnalyzer.GetNodesFromTextRange(
        ref selStart, ref selLength, nodesToSearch);

// 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 (Microsoft.Ink.Stroke theStroke
    in this.theInkAnalyzer.RootNode.Strokes)
{
    theStroke.DrawingAttributes =
        new Microsoft.Ink.DrawingAttributes(Color.Black);
}

// Next, set all selected sub nodes to red
foreach (Microsoft.Ink.ContextNode theContextNode in selectedSubNodes)
{
    foreach (Microsoft.Ink.Stroke theStroke in theContextNode.Strokes)
    {
        theStroke.DrawingAttributes =
            new Microsoft.Ink.DrawingAttributes(Color.Red);
    }
}

平台

Windows Vista

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

版本資訊

.NET Framework

支援版本:3.0

請參閱

參考

InkAnalyzer 類別

InkAnalyzer 成員

GetNodesFromTextRange 多載

Microsoft.Ink 命名空間