共用方式為


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" 保持不變。

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

呼叫 ModifyTopAlternate 方法可能會修改 RecognitionResult 物件的 TopStringTopAlternate 屬性。

範例

這個 C# 範例會追蹤 RecognitionResult 物件及其 RecognitionAlternate 物件。接著再將 RecognitionResult 物件與藉由使用 SetResultOnStrokes 方法所辨識的 Stroke 物件一起儲存。最後,範例會根據使用者輸入來修改 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® Visual Basic® .NET 範例會追蹤 RecognitionResult 物件及其 RecognitionAlternate 物件。接著再將 RecognitionResult 物件與藉由使用 SetResultOnStrokes 方法所辨識的 Stroke 物件一起儲存。最後,範例會根據使用者輸入來修改 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