在我previus後我問如何創建一組N拖動按鈕,它工作得很好n個按鈕,但我現在的工作在以下方面:調用事件的形式
我放在圖像窗體,並加載了一個座標矩陣,以便當我也拖動圖像時,按鈕「跟隨圖像」,我試圖通過調用一個事件來完成它,當按鈕完成拖動時,調用一個事件並進行轉換「圖像座標」到「形成座標」。它工作正常,但只有一個,但問題出現時,我放置n個按鈕,因爲我不知道如何「識別」哪個按鈕稱爲事件,我會告訴你我是如何做我的東西:
int x, y;
//Creates a set of four buttons with an icon
for (int i = 0; i < 4; i++)
{
x = rnd.Next(1, this.Width - 30);
y = rnd.Next(1, this.Height - 30);
botonCustom newboton = new botonCustom(32, 32, new Point(x, y), imageList1);
//New event for each button (Is it ok to do?)
//I tried to call the same function newboton_Move, since i do not know how to create an event for each button
newboton.Move += new EventHandler(newboton_Move);
//Name the button and writes it on a lablel
newboton.Description = EtiDiamond[i];
DiamondButton.Add(newboton);
this.Controls.Add(newboton);
}
這裏是被調用的函數:
private void newboton_Move(object sender, EventArgs e)
{
// Here i use the coordinates transform method, i won't place the code because
// its too big and it goes against the rules :P, i think if i could somehow know which button called this...
}
感謝您閱讀本
您必須將發件人轉換爲按鈕。然後你就會知道哪一個叫這個事件。 –
也感謝你 – NelsonRios