J'ai résolu le problème. il s'agissait de réorganiser le flux logique.
La solution couvre 3 événements souris MouseEnter, MouseMove, MouseLeave.
private PictureBox HomeLastPicBox = null;
private TableLayoutPanelCellPosition HomeLastPosition = new TableLayoutPanelCellPosition(0, 0);
private void HomeTableLayoutPanel_MouseMove(object sender, MouseEventArgs e)
{
PictureBox HomeCurrentPicBox = (PictureBox)(HomeTableLayoutPanel.GetChildAtPoint(e.Location));
if ((HomeCurrentPicBox != HomeLastPicBox) && (HomeCurrentPicBox != null))
{
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(HomeCurrentPicBox);
if (GameModel.HomeCellStatus(HomeCurrentPosition.Column, HomeCurrentPosition.Row) == Cell.cellState.WATER)
{
HomeCurrentPicBox.Image = Properties.Resources.scan;
HomeLastPosition = HomeCurrentPosition;
}
gameFormToolTip.SetToolTip(HomeTableLayoutPanel, GameModel.alphaCoords(HomeTableLayoutPanel.GetCellPosition(HomeCurrentPicBox).Column) + "," + HomeTableLayoutPanel.GetCellPosition(HomeCurrentPicBox).Row);
}
}
private void HomeTableLayoutPanel_MouseEnter(object sender, EventArgs e)
{
Point p = HomeTableLayoutPanel.PointToClient(Control.MousePosition);
PictureBox HomeCurrentPicBox = (PictureBox)(HomeTableLayoutPanel.GetChildAtPoint(p));
if (HomeCurrentPicBox != null)
{
TableLayoutPanelCellPosition HomeCurrentPosition = HomeTableLayoutPanel.GetCellPosition(HomeCurrentPicBox);
if (GameModel.HomeCellStatus(HomeCurrentPosition.Column, HomeCurrentPosition.Row) == Cell.cellState.WATER)
{
HomeCurrentPicBox.Image = Properties.Resources.scan;
}
gameFormToolTip.SetToolTip(HomeTableLayoutPanel, GameModel.alphaCoords(HomeTableLayoutPanel.GetCellPosition(HomeCurrentPicBox).Column) + "," + HomeTableLayoutPanel.GetCellPosition(HomeCurrentPicBox).Row);
}
}
private void HomeTableLayoutPanel_MouseLeave(object sender, EventArgs e)
{
if (GameModel.HomeCellStatus(HomeLastPosition.Column, HomeLastPosition.Row) == Cell.cellState.WATER)
{
HomeLastPicBox = (PictureBox)HomeTableLayoutPanel.GetControlFromPosition(HomeLastPosition.Column, HomeLastPosition.Row);
HomeLastPicBox.Image = Properties.Resources.water;
gameFormToolTip.SetToolTip(HomeTableLayoutPanel, GameModel.alphaCoords(HomeTableLayoutPanel.GetCellPosition(HomeLastPicBox).Column) + "," + HomeTableLayoutPanel.GetCellPosition(HomeLastPicBox).Row);
}
}
Je pensais que je posterais la solution pour les futurs chercheurs de connaissances.
merci.
c'est une excellente information. très utile à savoir. Merci. Y at-il un contrôle pour cela? c'est à dire. désactiver le traitement si la souris se déplace trop vite? – iTEgg
Vous pouvez utiliser les crochets de la souris. Cela peut être utile: http://blogs.msdn.com/toub/archive/2006/05/03/589468.aspx – alemjerus
@alemjerus Y a-t-il de la documentation qui indique que l'intervalle est en effet de 20 ms? Je demande parce que j'essaie de contourner un problème et je veux m'assurer que l'intervalle est correct. – BryanJ