问候,我正在开发战舰克隆游戏,但我遇到了 TableLayoutPanel MouseLeave 事件的问题。
第一个鼠标移动:
private PictureBox HomeLastPicBox = new PictureBox();
private TableLayoutPanelCellPosition homeLastPosition = new TableLayoutPanelCellPosition(0, 0);
private void HomeTableLayoutPanel_MouseMove(object sender, MouseEventArgs e)
{
PictureBox NowPicControl = (PictureBox)(HomeTableLayoutPanel.GetChildAtPoint(e.Location));
if ((NowPicControl != null) && (NowPicControl != HomeLastPicBox))
{
HomeLastPicBox = (PictureBox)(HomeTableLayoutPanel.GetControlFromPosition(homeLastPosition.Column, homeLastPosition.Row));
if (GameModel.HomeCellStatus(homeLastPosition.Column, homeLastPosition.Row) == Cell.cellState.WATER)
{
HomeLastPicBox.Image = Properties.Resources.water;
}
TableLayoutPanelCellPosition homeCurrentPosition = HomeTableLayoutPanel.GetCellPosition(NowPicControl);
if (GameModel.HomeCellStatus(homeCurrentPosition.Column, homeCurrentPosition.Row) == Cell.cellState.WATER)
{
NowPicControl.Image = Properties.Resources.scan;
}
homeLastPosition = homeCurrentPosition;
}
}
这似乎运行正常。
现在是 MouseLeave 事件:
private void HomeTableLayoutPanel_MouseLeave(object sender, EventArgs e)
{
MessageBox.Show("col " + homeLastPosition.Column.ToString() + " row " + homeLastPosition.Row.ToString());
if (GameModel.HomeCellStatus(homeLastPosition.Column, homeLastPosition.Row) == Cell.cellState.WATER)
{
HomeLastPicBox.Image = Properties.Resources.water;
MessageBox.Show("hi");
}
HomeLastPicBox = new PictureBox();
}
这表现得很奇怪。它通过代码,甚至显示“HI”,但 PictureBox 图像未更改为水。关于为什么的任何想法?这不会一直发生,只是偶尔会发生。
上面的代码所做的基本上是扫描表格单元格,如果单元格内容是 WATER,那么它将表格单元格图像更新为 SCAN,并且随着用户继续前进,它将单元格图像切换回 WATER。
希望这是足够的信息。请询问是否需要更多。
先感谢您。
ps这是尝试像mouseover和mouseexit这样的javascript。
我已经取得了一些进展。原来在 MouseLeave 之后,MouseMove 被再次调用,因此结果我正在经历。
只需要以我认为的另一种方式对其进行逻辑。