【问题标题】:wpf c# button wait for a button presswpf c#按钮等待按钮按下
【发布时间】:2013-03-31 02:18:29
【问题描述】:

好吧,我是编码的初学者

所以我要做的是等待的按钮
用户单击多个其他按钮之一继续

void Mainbutton()
{  

    //the program run throw so method  

    //Wait for the user to choose one  button (I made a numeric pad with buttons)  

    //Then use this information to work

}

我知道我的英语不是很好 非常感谢

【问题讨论】:

  • 如果我理解正确,您是不是在尝试按下按钮,我们称之为“开始”并在单击另一个按钮后执行该工作?
  • 我正在尝试做一个在某个点停止运行的按钮,等待用户点击另一个按钮然后继续
  • 您需要按照教程进行操作;试试here。

标签: c# wpf events button


【解决方案1】:

试试这样的:

bool gotResponse = false;
//you need to run MainTask in a different thread
Thread thread = new Thread(new ThreadStart(DoWork));
thread.Start();

void DoWork()
{
     //do some work
     //when something else needed from user then popup message
     MessageBox.Show("say whatever you need to say");
     while(!gotResponse)
     {
          //note: this loop doesn't stop until gotResponse = true; 
     }
     //do rest of your work
}

private button_Click(object sender, RoutedEventArgs e)
{
     gotResponse = true;
}

【讨论】:

    猜你喜欢
    • 2013-08-02
    • 2011-08-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-03
    相关资源
    最近更新 更多