傳回子代 ContextNode 物件集合,這些物件都與已辨識字串中指定的文字範圍相關聯。
命名空間: System.Windows.Ink
組件: IAWinFX (在 IAWinFX.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%
傳回值
型別:System.Windows.Ink.ContextNodeCollection
子代 ContextNode 物件集合,這些物件都與已辨識字串中指定的文字範圍相關聯。
備註
start 和 length 參數都是可變更的參考值,用以指定與所傳回 ContextNodeCollection 相關聯的整個字串。例如,GetRecognizedString 的傳回值為 "I am late",而且您傳入 start = 6 和 length = 1 兩個值,表示這些參數對應於 "a" 這個字母。因此,ContextNodeCollection 可能只包含一個 ContextNode,也就是對應於 "late" 一字的 InkWordNode。在這個範例中,start 的值會變更為 5,而且 length 的值會變更為 4 (表示對應於 "late" 這一整個字)。
範例
下列程式碼範例會使用 GetNodesFromTextRange 方法,標示對應於選定文字的筆劃。範例程式碼會假設名為 theResultsTextBox 的 TextBox 之 Text 屬性設定為 GetRecognizedString 方法所傳回的值,而且使用者已從 theResultsTextBox 中選取一些文字。這個範例也會假設有名為 theInkAnalyzer 的 InkAnalyzer。
Dim theRootNode As RootNode = CType(theInkAnalyzer.RootNode, RootNode)
' First, set all strokes to black
For Each stroke As Stroke In theRootNode.Strokes
stroke.DrawingAttributes.Color = Colors.Black
Next stroke
' Find out what's been selected in the text box
Dim selStart As Integer = theResultsTextBox.SelectionStart
Dim selLength As Integer = theResultsTextBox.SelectionLength
' Do nothing if no text is selected.
If selLength = 0 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
' Next, set all selected sub nodes to red
Dim node As ContextNode
For Each node In selectedSubNodes
Dim stroke As Stroke
For Each stroke In node.Strokes
stroke.DrawingAttributes.Color = Colors.Red
Next stroke
Next node
RootNode theRootNode = (RootNode)theInkAnalyzer.RootNode;
// First, set all strokes to black
foreach (Stroke stroke in theRootNode.Strokes)
stroke.DrawingAttributes.Color = Colors.Black;
// Find out what's been selected in the text box
int selStart = theResultsTextBox.SelectionStart;
int selLength = theResultsTextBox.SelectionLength;
// Do nothing if no text is selected.
if (selLength == 0)
{
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;
// Next, set all selected sub nodes to red
foreach (ContextNode node in selectedSubNodes)
{
foreach (Stroke stroke in node.Strokes)
{
stroke.DrawingAttributes.Color = Colors.Red;
}
}
平台
Windows Vista
.NET Framework 和 .NET Compact Framework 並不支援各種平台的所有版本。如需支援平台版本的相關資訊,請參閱 .NET Framework 系統需求。
版本資訊
.NET Framework
支援版本:3.0