2013-04-08 171 views
-5

好的,我在编码WPF C#按钮,等待按下按钮

初学者那么我现在要做的是按钮谁要去等待
用户点击其他多个按钮的一个继续

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 

} 

我知道我的英语心不是那么好 非常感谢

+0

如果我理解正确,您是否尝试按下按钮,我们将其称为“开始”,并在点击另一个按钮后执行该任务? – Dilshod 2013-04-08 20:50:17

+0

我试图做一个按钮,停止在某个点运行,等待用户点击其他按钮,然后继续 – 2013-04-08 20:54:49

+1

您需要遵循教程;尝试[这里](http://msdn.microsoft.com/en-us/library/ms752299.aspx)。 – 2013-04-08 21:00:28

回答

-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; 
}