C#經由過程拜托挪用Button單擊事宜的辦法。本站提示廣大學習愛好者:(C#經由過程拜托挪用Button單擊事宜的辦法)文章只能為提供參考,不一定能成為您想要的結果。以下是C#經由過程拜托挪用Button單擊事宜的辦法正文
這裡引見經由過程拜托撤消Button事宜switch-case的辦法。須要留意的是,事前要按次序在各個Button的Tag屬性中設置0、1、2、3……等序號,其感化請詳看代碼。
/*界說拜托*/
public delegate 類型或viod MethodDelegate(參數1, 參數2);
private void buttonC_Click(object sender, EventArgs e)
{
Button button = (Button)sender;
/*向拜托添加辦法*/
MethodDelegate methodDelegate = 你的辦法1;
methodDelegate +=你的辦法2;
methodDelegate +=你的辦法3;
……….
/*轉換成數組*/
Delegate[] delegates = methodDelegate.GetInvocationList();
/*依據button.Tag中序號選擇拜托列表數組中響應辦法*/
MethodDelegate method = (MethodDelegate)delegates[Convert.ToInt16(button.Tag)];
/*履行*/
類型 i = method(參數1, 參數2);
}
Private 類型或viod 你的辦法1 (參數1, 參數2)
{
……….
}
Private 類型或viod 你的辦法2 (參數1, 參數2)
{
……….
}
Private 類型或viod 你的辦法3 (參數1, 參數2)
{
……….
}
以上所述就是本文的全體內容了,願望年夜家可以或許愛好。