2017-07-08 60 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 
} 
相關問題