如何确定哪个鼠标按钮(例如LeftButton)刚刚被释放

本文关键字:LeftButton 释放 例如 何确定 鼠标 按钮 | 更新日期: 2023-09-27 17:49:34

我可以很容易地检查哪个按钮当前处于按下状态或释放状态。例如,要检查LeftButton当前是否被释放,我可以使用:

void mouse_event_handler(object sender, MouseButtonEventArgs e)
{
    if (e.LeftButton == MouseButtonState.Released)
    {
        // left button is released
    }
}

我的问题是:我如何确定哪个鼠标按钮(例如LeftButton)刚刚从按下到释放的状态?上述方法将无法确定这一点,因为无论MiddleButtonRightButton哪个按钮先前被释放(即它只检查当前状态),它也将为真。我不确定C#/WPF是否支持这个。我想要这样的:

if (e.LeftButton == MouseButtonState.Just_Released)

注::我知道一种方法,通过使用一个额外的标志,当鼠标按钮按下,然后检查这个标志。

如何确定哪个鼠标按钮(例如LeftButton)刚刚被释放

你可以使用MouseButtonEventArgs类的ChangedButton属性

if (e.ChangedButton == MouseButton.Left)
{
    // Only occurs when the Left button is released
}
if (e.LeftButton == MouseButtonState.Released)
{
    // Occurs everytime a button is released (doesnt matter which one) AND the left mouse button is in released mode
}

更多信息:http://msdn.microsoft.com/en-us/library/system.windows.input.mousebuttoneventargs.changedbutton(v=vs.110).aspx