2017-07-08 57 views
-1

我这个代码:如何在单击按钮时调用方法并传递参数?

 correctButton.Clicked += (sender, e) => 
     { 
      App.DB.IncrementScore(AS.cfs, AS.phrase); 

      correctAns++; 
      AS.pointsCount[(int)AS.cfs]++; 
      scoreCountLabel.Text = FontAwesome.FAStop.Repeat(correctAns); 
      Device.StartTimer(TimeSpan.FromSeconds(0.5),() => 
      { 
       switch (AS.cardOrder) 
       { 
        case CardOrder.FirstToLast: 
         AS.orderPhraseIndex++; 
         AS.phraseIndexList.Add(AS.orderPhraseIndex); 
         getPhraseFirstToLast(); 
         break; 
        case CardOrder.Random: 
         getRandomNumber(); 
         getRandomPhrase(); 
         break; 
       } 
       return false; 
      }); 
     }; 

我想动议的运行成一个方法的代码,并传递参数也。但是如何在单击correctButton时调用该方法?

+1

使一个方法'空隙的MyMethod(对象发件人,EventArgs的)'并将其附加事件:'correctButton.Clicked + =的MyMethod;' – ASh

+0

有https://msdn.microsoft.com/en的读-us/library/0s21cwxk.aspx。 – mjwills

回答

2
correctButton.Clicked += correctButtonClicked; 

protected void correctButtonClicked(object sender, EventArgs e) 
{ 
    // code goes here 
} 
相关问题