//鼠标点击事件 private void Astar_MouseDown(object sender, MouseEventArgs e) { myButton = (Astar_Grid)sender;//接收对象 int x = myButton.X; int y = myButton.Y; //todo 判断没按到按钮上的情况 if (mychoose == MyChoose.wall) { if (sender.GetType().Name == "Astar") { return; } myBtn[x, y].BackColor = Color.Black; //界面 R[x, y] = 0; //属性 } else if (mychoose == MyChoose.start) { myBtn[x, y].BackColor = Color.Transparent; myBtn[x, y].BackColor = Color.Green; strPoint.x = x; strPoint.y = y; } else if (mychoose == MyChoose.destination) { myBtn[x, y].BackColor = Color.Transparent; myBtn[x, y].BackColor = Color.Red; desPoint.x = x; desPoint.y = y; } }
private void Astar_Load(object sender, EventArgs e) { //创建20*20个按钮 for (int i = 0; i < 20; i++) { for (int j = 0; j < 20; j++) { myBtn[i, j] = new Astar_Grid(); myBtn[i, j].X = i; myBtn[i, j].Y = j; myBtn[i, j].Size = new Size(20, 20); myBtn[i, j].Location = new Point(i * 20, j * 20); this.Controls.Add(myBtn[i, j]); //生成按钮 myBtn[i, j].MouseDown += Astar_MouseDown; //挂载事件 R[i, j] = 1; } } }