Yop*_*Yop 0 c# recursion events
我正在寻找一种递归调用事件的方法.我有以下内容
private void btn_choose_Click(object sender, EventArgs e)
{
// switch statement to take the user input and decide the outcome.
switch (Convert.ToInt32(nud_cat_chooser.Value))
{
case 1:
if (Convert.ToInt32(lbl_p1_cat_1_value.Text) == Convert.ToInt32(lbl_p2_cat_1_value.Text))
{
MessageBox.Show("Stalemate");//message box to inform the user of a statemate.
playingcards card1 = player1.Dequeue();//creates tempoary instance of the abstract class playign cards to store the cards
playingcards card2 = player2.Dequeue();//creates tempoary instance of the abstract class playign cards to store the cards
assign_Values();
btn_choose_Click();
}
....
}
}
Run Code Online (Sandbox Code Playgroud)
我想再次调用btn_choose_click事件来解决僵局.将使用assign方法为标签指定值.但是我正在努力实现对btn_choose_click()的调用; 我必须通过哪些论据?有人能告诉我一个例子吗?
谢谢 :)
小智 5
通过发件人和e.
但是,如果我是你,我只需将逻辑从处理程序中拉出来并将其放入方法中.明确地调用处理程序是一种非常糟糕的做法.事件处理程序应该响应事件.如果你要在你的处理程序中设置一个断点,你会期望它只是在调试时被击中以响应句柄中的事件,而不是因为你班级中其他地方的其他方法称它.例如:
private void btn_choose_Click(object sender, EventArgs e)
{
NewMethod();
}
private void NewMethod()
{
switch (Convert.ToInt32(nud_cat_chooser.Value))
{
case 1:
if (Convert.ToInt32(lbl_p1_cat_1_value.Text) == Convert.ToInt32(lbl_p2_cat_1_value.Text))
{
MessageBox.Show("Stalemate");//message box to inform the user of a statemate.
playingcards card1 = player1.Dequeue();//creates tempoary instance of the abstract class playign cards to store the cards
playingcards card2 = player2.Dequeue();//creates tempoary instance of the abstract class playign cards to store the cards
assign_Values();
NewMethod();
}
Run Code Online (Sandbox Code Playgroud)