【发布时间】:2018-05-03 20:28:31
【问题描述】:
我在窗体数据网格视图中有一个二维按钮数组。当用户单击按钮时,我想将按钮的 x,y 位置传递给函数以执行另一项任务。目前,我正在使用在表单加载时运行的代码:
for (int x = 0; x < 8; x++)
{
for (int y = 0; y < 8; y++)
{
BoardButtons[x, y] = new Button();
Controls.Add(BoardButtons[x, y]);
BoardButtons[x, y].Visible = true;
BoardButtons[x, y].Click += (s, ev) =>
{
MyFunction(x, y);
};
}
}
但是,每次我单击表单中的按钮时,它总是将 8 作为 x,y 坐标传递给函数。只是想知道我的代码是否有问题?
【问题讨论】: