我的crate矩形代码:
Rectangle[] myRectangle = new Rectangle[100];
for(int i=1;i<=100;i++)
{
myRectangle[i] = new Rectangle();
// another code for create myRectangle[i]
}
当MouseEnter Rectangle [X]和我想做某事时。我该怎么办? 谢谢。
答案 0 :(得分:0)
把它放在这里;
Rectangle[] myRectangle = new Rectangle[100];
for(int i = 0; i < 100; i++)
{
myRectangle[i] = new Rectangle();
myRectangle[i].Tag = i;
myRectangle[i].MouseEnter += MouseEnter;
}
private void MouseEnter(object sender, MouseEventArgs e)
{
Rectangle rect = (Rectangle)sender;
int idx = (int)rect.Tag;
MessageBox.Show(idx.ToString());
}