我们如何使Windows窗体应用程序的事件等待用户输入?
就像我命令我的电脑关机或注销或休眠或睡眠一样,然后它确认我真的想要关机/注销或休眠或睡觉如果我说是执行动作然后它执行否则,如果我否认或说中止它会中止该操作。
但不仅仅是在没有确认命令后直接关闭pc。
我在语音识别计算机上使用它而不是语音命令系统我不想出现一个消息框并且问我是或否我让它说话并问我是否想要这样做但是它不是在等我的回答。
当前代码:
string speech = e.Result.Text.ToString();
string [] terminateFind = speech.Split('');
if (terminateFind[0]=="Terminate"||terminateFind[0]=="Kill")
{
speech = "";
for (int i = 0; i < terminateFind.Length-1; i++)
{
speech += terminateFind[i]+" ";
}
KillingProcess = Int32.Parse(terminateFind[terminateFind.Length-1]);
}
switch (speech) {
case "Terminate Process Number ":
case "Kill Process Number ":
case "Close Process Number ":
string Procr = listBox1.Items[KillingProcess - 1].ToString();
string[]Kilproc = Procr.Split('-');
int Pid = Process.GetProcessesByName(ProcName[KillingProcess - 1])[0].Id;
Travis.Speak("Terminating Porcess named : " + Kilproc[Kilproc.Length - 1]);
Thread.Sleep(10000);
// sRecog.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(sRecog_SpeechRecognized);
if (e.Result.Text.ToString() == "Abort") {
AbortTheComand = true;
}
if (AbortTheComand == false) {
Process.GetProcessById(Pid, ".").Kill();
} else {
Travis.Speak("Operation Terminated by user : ");
}
break;
}
答案 0 :(得分:1)
欢迎使用Stackoverflow。
首先重要的是,你应该发布你在问题中尝试过的代码。
我假设您的Action Button
中有Form
,其Click Event
负责处理您提到的所有内容。
private void Action_Button_Click(object sender, EventArgs e)
{
//Some Code...
//Decide whether to Shutdown.
DialogResult dr = MessageBox.Show("Are you sure you want to shutdown Windows ?", "App Name", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk);
if (dr == DialogResult.Yes)
{
//Logic to Shutdown Windows.
}
else if (dr == DialogResult.No)
{
//React accordingly or do what you want.
}
//Some Code...
}
同样的代码也可用于决定Hibernate,Sleep或Log off事件。