2015-01-12 95 views
-3

我正在創建一個C#WinForms應用程序,它應該使用語音命令「exit」關閉應用程序。運算符+ =不能應用

但是它給了我一個例外:

運營商+ = cannnot應用於系統言語或主要方法

的操作數在此代碼:

public partial class Form1 : Form 
{ 
    SpeechRecognitionEngine sRecongize = new SpeechRecognitionEngine(); 

    private void Form1_Load(object sender, EventArgs e) 
    { 
     // Compiler error here: 
     sRecongize += sRecongize_SpeechRecognized; 
    } 

    private void sRecongize_SpeechRecognized(object sender, SpeechRecognizedEventArgs e) 
    { 
     if (e.Result.Text == "exit") 
     { 
      Application.Exit(); 
     } 
    } 
} 

哪有我訂閱一個活動?

+1

你缺少事件名稱。該行應該可以讀取'sRecognize.OnSomeEventName + = sRecognize_SpeechRecognized;' –

回答

5

您需要訂閱特定的事件,在這種情況下SpeechRecognized,而不是整個類:

sRecongize.SpeechRecognized += sRecongize_SpeechRecognized; 
相關問題