鼠标移动太快,无法捕获事件 [英] Mouse moves too fast to capture events

查看:185
本文介绍了鼠标移动太快,无法捕获事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这与以下内容有关:以前的问题

但是问题是我的代码只有当我将鼠标移动到TableLayoutPanel周围的时候才会失败。

BUT the question is my code only fails when i move the mouse really really fast over and around the TableLayoutPanel.

C#或Windows是否可以报告/ /由于快速的鼠标移动触发事件无序

is it possible that C# or windows are reporting/triggering events out of order due to the fast mouse movement?

如果是,我该如何更正?

if so, how do i correct it?

谢谢你我希望这不被认为是双重发布。如果是这样,道歉。

thank you. i hope this is not considered double posting. if so, apologies.

推荐答案

我解决了这个问题。这是一个重新排序逻辑流程的问题。

i solved the issue. it was a matter of reordering the logic flow.

解决方案跨越3个鼠标事件MouseEnter,MouseMove,MouseLeave。

the solution spans 3 mouse events 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);
        }
    }

我以为我会为未来的知识追求者发布解决方案

i thought i would post the solution for future knowledge seekers.

谢谢。

这篇关于鼠标移动太快,无法捕获事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆