2013-11-28 22 views
0

我試圖做一些搜索的最佳方式來做到這一點,但我不知道要搜索什麼;所以如果有人會介意的話,我希望在這裏得到一些幫助。注意Chatbot

在我的C#的形式,我有:

  • InputTextbox
  • OutputTextbox

我使用 「InputTextbox_KeyDown」 運行越來越多的 「如果」 語句。即:

if (e.KeyCode == Keys.Enter & InputputTextbox.Text.Contains("hello") 
OutputTextbox.Text = "hi there" 

我打電話的聊天機器人「便士」,並希望它只是尋求進一步的命令,一旦單詞「一分錢」被輸入到InputTextbox。 (即:如果用戶輸入「hello」,則不會發生任何事情,因爲他們沒有得到「Penny的」關注)。

事情是這樣的:

if (KeyCode == Keys.Enter & InputTextbox.Text.Contains("penny") 
then 
*look for the next InputTextbox.Text* 

這有任何意義嗎?

+3

*這是否有意義?*不是真的... – MarcinJuraszek

+0

對不起。啊...基本上我希望程序只在「輸入」字樣輸入InputTextbox並用「hi there」回覆後才執行命令。 –

+0

我編輯了你的標題。請參閱:「[應該在其標題中包含」標籤「](http://meta.stackexchange.com/questions/19190/)」,其中的共識是「不,他們不應該」。 –

回答

1

你可以只設置一個標誌,表明「一分錢」已進入

private bool _isActive = false; 

public void YourMethod() 
{ 
    if (!_isActive) 
    { 
     if (KeyCode == Keys.Enter && InputTextbox.Text.Contains("penny")) 
     { 
      _isActive = true; 
     } 
    } 
    else 
    { 
     if (e.KeyCode == Keys.Enter && InputputTextbox.Text.Contains("hello")) 
     { 
      OutputTextbox.Text = "hi there"; 
     } 

     // other if's 
    } 
} 
0

想不出你只有這個你InputTextbox_KeyDown方法的頂部?

if(KeyCode != Keys.Enter) return; 
if(!InputTextbox.Text.Contains("penny")) return; 
/* 
* rest of chat responses 
*/