RecognitionResult.ModifyTopAlternate 方法

使用已知的 RecognitionAlternate 对象修改 RecognitionResult 对象。

命名空间:  Microsoft.Ink
程序集:  Microsoft.Ink(在 Microsoft.Ink.dll 中)

语法

声明
Public Sub ModifyTopAlternate ( _
    alternate As RecognitionAlternate _
)
用法
Dim instance As RecognitionResult
Dim alternate As RecognitionAlternate

instance.ModifyTopAlternate(alternate)
public void ModifyTopAlternate(
    RecognitionAlternate alternate
)
public:
void ModifyTopAlternate(
    RecognitionAlternate^ alternate
)
public void ModifyTopAlternate(
    RecognitionAlternate alternate
)
public function ModifyTopAlternate(
    alternate : RecognitionAlternate
)

参数

备注

默认情况下,RecognitionResult 对象的 TopString 属性对应于 TopAlternate 属性;不过,通过此方法可使用结果中最佳备选项之外的备选项。如果选择最佳备选项之外的备选项,实际上是通过结果的关联备选项的栅格 选择一条不同的路径。

若要检索可用于修改 RecognitionResult 对象的 RecognitionAlternate 对象,请调用 GetAlternatesFromSelection 方法。

此方法中使用的备选项可以是整句中的一个单词备选项。例如,对于针对“Hello World”调用 GetAlternatesFromSelection(0,5) 所获取的备选项,调用 ModifyTopAlternate 会更改“Hello”,但不会更改“World”。

备注

调用 ModifyTopAlternate 方法可以修改 RecognitionResult 对象的 TopStringTopAlternate 属性。

示例

此 C# 示例跟踪 RecognitionResult 对象及其 RecognitionAlternate 对象。然后,此示例通过使用 SetResultOnStrokes 方法将已识别的 Stroke 对象随 RecognitionResult 对象一起保存。最后,示例根据用户输入修改 RecognitionResult 对象的 TopAlternate 属性。

[C#]

// Declarations...
InkCollector theInkCollector;
Strokes theStrokes;
RecognizerContext theRecognizerContext;
RecognitionResult theRecognitionResult;

// Initialization...

// Initialize the recognizer's strokes
// and assign them to the context.
theStrokes = theInkCollector.Ink.Strokes;
theRecognizerContext = new RecognizerContext();
theRecognizerContext.Strokes = theStrokes;

// Install event handlers.
theRecognizerContext.RecognitionWithAlternates +=
    new RecognizerContextRecognitionWithAlternatesEventHandler(
        RecognitionWithAlternates_Event);

//...

// Recognition Event Handler
private void RecognitionWithAlternates_Event(
    object sender,
    RecognizerContextRecognitionWithAlternatesEventArgs e)
{
    // Save the RecognitionResult, and copy it to the strokes
    theRecognitionResult = e.Result;
    theRecognitionResult.SetResultOnStrokes();
}

// Modify the TopAlternate of the result
private void buttonAlt2_Click(object sender, System.EventArgs e)
{
    RecognitionAlternates theRecognitionAlternates =
        theRecognitionResult.GetAlternatesFromSelection(0, -1);
    theRecognitionResult.ModifyTopAlternate(theRecognitionAlternates[2]);
}

此 Microsoft(R) Visual Basic(R) .NET 示例跟踪 RecognitionResult 对象及其 RecognitionAlternate 对象。然后,此示例通过使用 SetResultOnStrokes 方法将已识别的 Stroke 对象随 RecognitionResult 对象一起保存。最后,示例根据用户输入修改 RecognitionResult 对象的 TopAlternate 属性。

[Visual Basic]

'Declarations...
Dim theInkCollector As InkCollector
Dim theStrokes As Strokes
Dim theRecognizerContext As RecognizerContext
Dim theRecognitionResult As RecognitionResult

'Initialization...

'Initialize the recognizer's strokes
'and assign them to the context.
theStrokes = theInkCollector.Ink.Strokes
theRecognizerContext = new RecognizerContext()
theRecognizerContext.Strokes = theStrokes

'Install event handlers.
AddHandler theRecognizerContext.RecognitionWithAlternates, _
AddressOf RecognitionWithAlternates_Event

'...

'Recognition Event Handler
Private Sub RecognitionWithAlternates_Event( _
ByVal sender As Object, _
ByVal e As RecognizerContextRecognitionWithAlternatesEventArgs)
    'Save the RecognitionResult, and copy it to the strokes.
    theRecognitionResult = e.Result
    theRecognitionResult.SetResultOnStrokes()
End Sub

'Modify the TopAlternate of the result
Private Sub ButtonAlt2_Click(object sender, System.EventArgs e) _
Handles ButtonAlt2.Click
    RecognitionAlternates theRecognitionAlternates =
        theRecognitionResult.GetAlternatesFromSelection(0, -1)
    theRecognitionResult.ModifyTopAlternate(theRecognitionAlternates(2))
End Sub

平台

Windows Vista

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

版本信息

.NET Framework

受以下版本支持:3.0

另请参见

参考

RecognitionResult 类

RecognitionResult 成员

Microsoft.Ink 命名空间

RecognitionAlternate

RecognitionResult.GetAlternatesFromSelection

RecognitionResult.TopAlternate

RecognitionResult.TopString