다음을 통해 공유


ContextNodeBase 클래스

업데이트: 2007년 11월

잉크 분석 도중 만들어진 개체 트리의 노드를 나타냅니다.

네임스페이스:  System.Windows.Ink.AnalysisCore
어셈블리:  IACore(IACore.dll)

구문

‘선언
Public Class ContextNodeBase
‘사용 방법
Dim instance As ContextNodeBase
public class ContextNodeBase
public ref class ContextNodeBase
public class ContextNodeBase
public class ContextNodeBase

예제

이 예제에서는 이름이 theInkAnalyzer인 InkAnalyzerBase 개체를 사용합니다. 해당 개체의 ContextNodeBase 트리를 사용하여 이름이 theTreeView인 System.Windows.Forms.TreeView를 채웁니다. 트리 뷰에서 노드를 선택하면 해당 스트로크가 빨간색으로 나타나도록 설정됩니다. Tag 속성은 트리 노드와 해당 노드가 나타내는 컨텍스트 노드를 서로 매핑하는 데 사용됩니다.

Private Sub BuildTree()
    Me.theTreeView.Nodes.Clear()
    Dim rootNode As New TreeNode(Me.theInkAnalyzerBase.RootNode.ToString())
    Me.theTreeView.Nodes.Add(rootNode)
    rootNode.Tag = Me.theInkAnalyzerBase.RootNode

    WalkTree(Me.theInkAnalyzerBase.RootNode, rootNode)

End Sub 'BuildTree


Private Sub WalkTree(ByVal parentContextNode As ContextNodeBase, ByVal parentTreeNode As TreeNode)

    Dim cNode As ContextNodeBase

    For Each cNode In parentContextNode.SubNodes

        Dim newTNode As New TreeNode(cNode.ToString())

        If cNode.Type = System.Windows.Ink.AnalysisCore.ContextNodeTypeBase.InkWord AndAlso _
           cNode.ContainsPropertyData(PropertyGuidsForContextNodesBase.RecognizedString) Then

            newTNode.Text = newTNode.Text + _
                ": " + CType(cNode.GetPropertyData(PropertyGuidsForContextNodesBase.RecognizedString), _
                String)

        ElseIf cNode.Type = System.Windows.Ink.AnalysisCore.ContextNodeTypeBase.InkDrawing AndAlso _
               cNode.ContainsPropertyData(PropertyGuidsForContextNodesBase.ShapeName) Then

            Dim shapeName As String = CType(cNode.GetPropertyData(PropertyGuidsForContextNodesBase.ShapeName), _
                String)

            If shapeName <> "" Then
                newTNode.Text = newTNode.Text + ": " + shapeName
            End If

        End If

        WalkTree(cNode, newTNode)
        parentTreeNode.Nodes.Add(newTNode)

        ' Add the context node as a tag of the tree node
        newTNode.Tag = cNode
    Next cNode

End Sub 'WalkTree

Private Sub theTreeView_AfterSelect(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles theTreeView.AfterSelect
    ' Get the context node
    Dim selectedNode As ContextNodeBase = CType(e.Node.Tag, ContextNodeBase)

    MarkNodeAsRed(selectedNode)

    timeStampLabel.Text = ""

    ' Show selected results
    If Not (selectedNode Is Nothing) Then

        If (selectedNode.ContainsPropertyData(PropertyGuidsForContextNodesBase.RecognizedString) AndAlso _
           (selectedNode.Type = System.Windows.Ink.AnalysisCore.ContextNodeTypeBase.WritingRegion OrElse _
            selectedNode.Type = System.Windows.Ink.AnalysisCore.ContextNodeTypeBase.Paragraph OrElse _
            selectedNode.Type = System.Windows.Ink.AnalysisCore.ContextNodeTypeBase.CustomRecognizer OrElse _
            selectedNode.Type = System.Windows.Ink.AnalysisCore.ContextNodeTypeBase.Object OrElse _
            selectedNode.Type = System.Windows.Ink.AnalysisCore.ContextNodeTypeBase.Line)) Then

            selectedResultsTextBox.Text = _
                CType(selectedNode.GetPropertyData(PropertyGuidsForContextNodesBase.RecognizedString), String)

        ElseIf (selectedNode.Type = System.Windows.Ink.AnalysisCore.ContextNodeTypeBase.InkWord) Then
            Dim parentNode As ContextNodeBase = selectedNode.ParentNode
            If (parentNode.Type = System.Windows.Ink.AnalysisCore.ContextNodeTypeBase.Line AndAlso _
                    parentNode.ContainsPropertyData(PropertyGuidsForContextNodesBase.RecognizedString)) Then

                ' Put parent line's recognized string into the text box
                selectedResultsTextBox.Text = _
                    CType(parentNode.GetPropertyData(PropertyGuidsForContextNodesBase.RecognizedString), String)

                ' Select the text that corresponds to the ink word
                Dim subNodes As New ContextNodeBaseCollection(theInkAnalyzerBase)
                subNodes.Add(selectedNode)
                Dim start As Integer
                Dim length As Integer
                theInkAnalyzerBase.GetTextRangeFromNodes(subNodes, start, length)
                If (start >= 0 AndAlso length > 0) Then
                    selectedResultsTextBox.Select(start, length)
                End If
            End If
        ElseIf (selectedNode.Type = System.Windows.Ink.AnalysisCore.ContextNodeTypeBase.InkDrawing AndAlso _
                selectedNode.ContainsPropertyData(PropertyGuidsForContextNodesBase.ShapeName)) Then

            selectedResultsTextBox.Text = _
                CType(selectedNode.GetPropertyData(PropertyGuidsForContextNodesBase.ShapeName), String)

        End If
    End If

    Me.currentNode = selectedNode

End Sub 'theTreeView_AfterSelect


Private Sub MarkNodeAsRed(ByVal selectedNode As ContextNodeBase)
    Dim selectedNodeStrokes As Strokes = Nothing

    If Not selectedNode Is Nothing Then
        selectedNodeStrokes = theInk.CreateStrokes(selectedNode.GetStrokeIds())
    End If

    ' Set all node strokes to black, but this one to red
    Dim stroke As Stroke
    For Each stroke In Me.theInkCollector.Ink.Strokes
        If (Not selectedNodeStrokes Is Nothing And _
                selectedNodeStrokes.Contains(stroke)) Then

            stroke.DrawingAttributes = New DrawingAttributes(Color.Red)
        Else
            stroke.DrawingAttributes = Me.theInkCollector.DefaultDrawingAttributes
        End If
    Next

    theNotesPanel.Refresh()
End Sub


private void BuildTree()
{
    this.theTreeView.Nodes.Clear();
    TreeNode rootNode =
        new TreeNode(this.theInkAnalyzerBase.RootNode.ToString());
    this.theTreeView.Nodes.Add(rootNode);
    rootNode.Tag = this.theInkAnalyzerBase.RootNode;

    WalkTree(this.theInkAnalyzerBase.RootNode, rootNode);
}

private void WalkTree(
    System.Windows.Ink.AnalysisCore.ContextNodeBase parentContextNode, TreeNode parentTreeNode)
{
    foreach (ContextNodeBase cNode in parentContextNode.SubNodes)
    {
        TreeNode newTNode = new TreeNode(cNode.ToString());
        if ((cNode.Type == System.Windows.Ink.AnalysisCore.ContextNodeTypeBase.InkWord) &&
             cNode.ContainsPropertyData(PropertyGuidsForContextNodesBase.RecognizedString))
        {
            // Get the recognized string
            newTNode.Text += ": " +
                (string)cNode.GetPropertyData(PropertyGuidsForContextNodesBase.RecognizedString);
        }
        else if ((cNode.Type == System.Windows.Ink.AnalysisCore.ContextNodeTypeBase.InkDrawing) &&
                  cNode.ContainsPropertyData(PropertyGuidsForContextNodesBase.ShapeName))
        {
            newTNode.Text += ": " +
                (string)cNode.GetPropertyData(PropertyGuidsForContextNodesBase.ShapeName);
        }
        WalkTree(cNode, newTNode);
        parentTreeNode.Nodes.Add(newTNode);

        // Add the context node as a tag of the tree node
        newTNode.Tag = cNode;
    }
}

private void theTreeView_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e)
{
    // Get the context node
    ContextNodeBase selectedNode = (ContextNodeBase)e.Node.Tag;

    MarkNodeAsRed(selectedNode);

    timeStampLabel.Text = "";

    // Show selected results
    if (selectedNode != null)
    {
        if (selectedNode.ContainsPropertyData(PropertyGuidsForContextNodesBase.RecognizedString) &&
           (selectedNode.Type == System.Windows.Ink.AnalysisCore.ContextNodeTypeBase.WritingRegion ||
            selectedNode.Type == System.Windows.Ink.AnalysisCore.ContextNodeTypeBase.Paragraph ||
            selectedNode.Type == System.Windows.Ink.AnalysisCore.ContextNodeTypeBase.CustomRecognizer ||
            selectedNode.Type == System.Windows.Ink.AnalysisCore.ContextNodeTypeBase.Object ||
            selectedNode.Type == System.Windows.Ink.AnalysisCore.ContextNodeTypeBase.Line))
        {
            selectedResultsTextBox.Text =
                (string)selectedNode.GetPropertyData(PropertyGuidsForContextNodesBase.RecognizedString);
        }
        else if (selectedNode.Type == System.Windows.Ink.AnalysisCore.ContextNodeTypeBase.InkWord)
        {
            ContextNodeBase parentNode = selectedNode.ParentNode;
            if (parentNode.Type == System.Windows.Ink.AnalysisCore.ContextNodeTypeBase.Line &&
                parentNode.ContainsPropertyData(PropertyGuidsForContextNodesBase.RecognizedString))
            {
                // Put parent line's recognized string into the text box
                selectedResultsTextBox.Text =
                    (string)parentNode.GetPropertyData(PropertyGuidsForContextNodesBase.RecognizedString);

                // Select the text that corresponds to the ink word
                ContextNodeBaseCollection subNodes = new ContextNodeBaseCollection(theInkAnalyzerBase);
                subNodes.Add(selectedNode);
                int start;
                int length;
                theInkAnalyzerBase.GetTextRangeFromNodes(subNodes, out start, out length);
                if (start >= 0 && length > 0)
                {
                    selectedResultsTextBox.Select(start, length);
                }
            }
        }
        else if (selectedNode.Type == System.Windows.Ink.AnalysisCore.ContextNodeTypeBase.InkDrawing &&
                 selectedNode.ContainsPropertyData(PropertyGuidsForContextNodesBase.ShapeName))
        {
            selectedResultsTextBox.Text =
                (string)selectedNode.GetPropertyData(PropertyGuidsForContextNodesBase.ShapeName);

        }

        if (selectedNode.Type == System.Windows.Ink.AnalysisCore.ContextNodeTypeBase.InkWord)
        {
            // Show the time stamp
            if (selectedNode.ContainsPropertyData(this.timeStampGuid))
            {
                DateTime timeStamp =
                    (DateTime)selectedNode.GetPropertyData(this.timeStampGuid);
                timeStampLabel.Text = timeStamp.ToShortTimeString();
            }

            // Snippet to demonstrate GetPropertyDataIds
            Guid[] propertyDataIds = selectedNode.GetPropertyDataIds();
            // Snippets to demonstrate loading and saving
            byte[] data = selectedNode.SavePropertiesData();
            if (!selectedNode.LoadPropertiesData(data))
                MessageBox.Show("Cannot load property data");
        }
    }
    this.currentNode = selectedNode;
}

private void MarkNodeAsRed(ContextNodeBase selectedNode)
{
    Strokes selectedNodeStrokes = null;

    if (selectedNode != null)
    {
        selectedNodeStrokes = theInk.CreateStrokes(selectedNode.GetStrokeIds());
    }

    // Set all node strokes to black, but this one to red
    foreach (Stroke stroke in this.theInkCollector.Ink.Strokes)
    {
        if (selectedNodeStrokes != null &&
            selectedNodeStrokes.Contains(stroke))
            stroke.DrawingAttributes = new DrawingAttributes(Color.Red);
        else
            stroke.DrawingAttributes = this.theInkCollector.DefaultDrawingAttributes;
    }

    theNotesPanel.Refresh();
}

상속 계층 구조

System.Object
  System.Windows.Ink.AnalysisCore.ContextNodeBase

스레드로부터의 안전성

이 형식의 모든 공용 static(Visual Basic의 경우 Shared) 멤버는 스레드로부터 안전합니다. 인터페이스 멤버는 스레드로부터 안전하지 않습니다.

플랫폼

Windows Vista, Windows XP SP2, Windows Server 2003

.NET Framework 및 .NET Compact Framework에서 모든 플랫폼의 전체 버전을 지원하지는 않습니다. 지원되는 버전의 목록을 보려면 .NET Framework 시스템 요구 사항을 참조하십시오.

버전 정보

.NET Framework

3.0에서 지원

참고 항목

참조

ContextNodeBase 멤버

System.Windows.Ink.AnalysisCore 네임스페이스

System.Windows.Ink.AnalysisCore.ContextNodeBase