我想按下一個按鈕,當按鈕被激活時,關閉我想要的應用程序。例如,如果我打開記事本,我想按下一個按鈕並關閉記事本。但由於某些原因,我不能使用kill
或close
命令,因爲它用紅色標出。我正在用C#構建這個應用程序。這是代碼。我不能在我的代碼中使用「kill」進程。 (用紅色下劃線)
public EventHandler<SpeechRecognizedEventArgs> sRecognized { get; set; }
public Form1()
{
InitializeComponent();
}
void sRecognize_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
if (e.Result.Text == "alice present")
{
SoundPlayer sndPlayer = new SoundPlayer(Ai.Properties.Resources.My_name_is_A_L_I_C_E);
sndPlayer.Play();
}
if (e.Result.Text == "open notepad")
{
Process notepad = Process.Start("notepad.exe");
}
if (e.Result.Text == "close notepad")
{
BtnN.PerformClick();
}
}
private void BtnN_Click(object sender, EventArgs e)
{
Process notepad = Process.Kill("notepad.exe");
}
'Kill'是一種實例方法,您試圖靜態調用它。找到你想要殺死的「notepad.exe」實例,創建一個Process並殺死它。 – CodeCaster
另外,請努力在網上格式化您的代碼,以便它是可讀的。你有太多空白。 – Dai
你喜歡讀自己的文章嗎? –