ContextNodeBase.Confirm 方法

设置确认类型,该类型限制 InkAnalyzerBase 可更改哪些关于节点的内容。

命名空间:  System.Windows.Ink.AnalysisCore
程序集:  IACore(在 IACore.dll 中)

语法

声明
Public Sub Confirm ( _
    type As ConfirmationType _
)
用法
Dim instance As ContextNodeBase
Dim type As ConfirmationType

instance.Confirm(type)
public void Confirm(
    ConfirmationType type
)
public:
void Confirm(
    ConfirmationType type
)
public void Confirm(
    ConfirmationType type
)
public function Confirm(
    type : ConfirmationType
)

参数

备注

使用 Confirm 可使最终用户能够确认 InkAnalyzerBase 已正确分析了笔画。调用 Confirm 之后,InkAnalyzerBase 在后期分析期间不会更改这些笔画的 ContextNodeBase 对象。

例如,如果最终用户书写单词“to”,然后应用程序调用 Analyze,则 InkAnalyzerBase 将创建一个具有值“to”的 InkWord 节点。如果最终用户随后在“to”后面添加“me”作为一个整词,并且应用程序再次调用 Analyze,则 InkAnalyzerBase 可能创建一个具有值“tome”的 InkWord 节点。但是,如果在首次调用 Analyze 之后,应用程序以值 NodeTypeAndProperties 对“to”节点 InkWord 调用 Confirm,则会发生不同的行为。当最终用户添加“me”,并且应用程序再次调用 Analyze 时,“to”节点不会更改。InkAnalyzerBase 将识别出“to me”对应的两个 InkWord 节点。

只能确认 InkWordInkDrawing 类型的 ContextNodeBase 对象。如果尝试对非叶节点调用 Confirm,则会引发 InvalidOperationException

如果调用 InkAnalyzerBase.RemoveStroke,而要移除的笔画与已确认的 ContextNodeBase 对象相关,则 ContextNodeBase 对象将自动设置为未确认。

如果 ContextNodeBase 对象已确认,则 SetStrokes、SetStrokeType 和 SetStrokesType 会引发 InvalidOperationException。如果源节点或目标节点已确认,则 ReparentStrokes 会引发异常。

示例

下面的示例是 Panel (theNotesPanel) 上的 MouseUp 事件的事件处理程序,该处理程序正在通过名为 theInkCollector 的 InkCollector 收集墨迹。应用程序有一个名为 confirmMode 的 Boolean 值,该值由名为 confirmMenuItem 的 MenuItem 进行设置。在“确认”模式下,用户单击一个词进行确认(如果该节点已确认,则关闭确认)。该示例将鼠标释放事件转换为墨迹坐标,同时使用 HitTestFindNodesOfType 查找相应的节点。在找到节点之后,调用 Confirm 以切换确认。最后,应用程序脱离“确认”模式。

Private Sub theNotesPanel_MouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles theNotesPanel.MouseUp
    If Me.confirmMode = True Then
        ' Translate coordinates into ink dimensions
        Dim hitPoint As New Point(e.X, e.Y)
        Dim panelGraphics As Graphics = Me.theNotesPanel.CreateGraphics()
        Me.theInkCollector.Renderer.PixelToInkSpace(panelGraphics, hitPoint)
        panelGraphics.Dispose()

        ' Find the strokes that the user selected
        Dim selectedStrokes As Strokes = Me.theInkCollector.Ink.HitTest(hitPoint, 10)

        ' The integer array must be exactly the right size. Arrays
        ' begin at zero, so the upper bound is selectedStrokes.Count - 1.
        Dim selectedStrokeIds(selectedStrokes.Count - 1) As Integer

        For i As Integer = 0 To selectedStrokes.Count - 1
            selectedStrokeIds(i) = selectedStrokes(i).Id
        Next

        ' Find the ink word nodes that correspond to those strokes
        Dim selectedNodes As ContextNodeBaseCollection = _
            Me.theInkAnalyzerBase.FindNodesOfType(System.Windows.Ink.AnalysisCore.ContextNodeTypeBase.InkWord, _
            selectedStrokeIds)

        ' Toggle the confirmation type on these nodes
        Dim selectedNode As ContextNodeBase
        For Each selectedNode In selectedNodes
            If selectedNode.IsConfirmed( _
               Windows.Ink.AnalysisCore.ConfirmationType.NodeTypeAndProperties) Then
                selectedNode.Confirm(System.Windows.Ink.AnalysisCore.ConfirmationType.None)
            Else
                selectedNode.Confirm(System.Windows.Ink.AnalysisCore.ConfirmationType.NodeTypeAndProperties)
            End If
        Next selectedNode

        ' No longer in "confirm" mode
        Me.confirmMode = False
        Me.ConfirmMenuItem.Checked = False
        Me.theInkCollector.Enabled = True
    End If

End Sub
private void theNotesPanel_MouseUp(object sender, MouseEventArgs e)
{
    if (this.confirmMode)
    {
        // Translate coordinates into ink dimensions
        Point hitPoint = new Point(e.X, e.Y);
        Graphics panelGraphics = this.theNotesPanel.CreateGraphics();
        this.theInkCollector.Renderer.PixelToInkSpace(panelGraphics, ref hitPoint);
        panelGraphics.Dispose();

        // Find the strokes that the user selected
        Strokes selectedStrokes = this.theInkCollector.Ink.HitTest(hitPoint, 10);

        int[] selectedStrokeIds = new int[selectedStrokes.Count];

        for (int i = 0; i < selectedStrokes.Count; i++)
        {
            selectedStrokeIds[i] = selectedStrokes[i].Id;
        }

        // Find the ink word nodes that correspond to those strokes
        ContextNodeBaseCollection selectedNodes =
            this.theInkAnalyzerBase.FindNodesOfType(System.Windows.Ink.AnalysisCore.ContextNodeTypeBase.InkWord,
            selectedStrokeIds);

        // Toggle the confirmation type on these nodes
        foreach (ContextNodeBase selectedNode in selectedNodes)
        {
            if (selectedNode.IsConfirmed(
                System.Windows.Ink.AnalysisCore.ConfirmationType.NodeTypeAndProperties))
            {
                selectedNode.Confirm(System.Windows.Ink.AnalysisCore.ConfirmationType.None);
            }
            else
            {
                selectedNode.Confirm(System.Windows.Ink.AnalysisCore.ConfirmationType.NodeTypeAndProperties);
            }
        }

        // No longer in "confirm" mode
        this.confirmMode = false;
        this.confirmMenuItem.Checked = false;
            this.theInkCollector.Enabled = true;
    }

}

平台

Windows Vista, Windows XP SP2, Windows Server 2003

.NET Framework 和 .NET Compact Framework 并不是对每个平台的所有版本都提供支持。有关支持的版本的列表,请参见.NET Framework 系统要求

版本信息

.NET Framework

受以下版本支持:3.0

另请参见

参考

ContextNodeBase 类

ContextNodeBase 成员

System.Windows.Ink.AnalysisCore 命名空间