Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何确定刚刚释放的鼠标按钮(如LeftButton)?_C#_Wpf_Event Handling_Mouseevent - Fatal编程技术网

C# 如何确定刚刚释放的鼠标按钮(如LeftButton)?

C# 如何确定刚刚释放的鼠标按钮(如LeftButton)?,c#,wpf,event-handling,mouseevent,C#,Wpf,Event Handling,Mouseevent,我可以轻松检查哪个按钮当前处于按下状态或释放状态。例如,要检查LeftButton当前是否已释放,我可以使用: void mouse_event_handler(object sender, MouseButtonEventArgs e) { if (e.LeftButton == MouseButtonState.Released) { // left button is released } } 我的问题是:如何确定哪个鼠标按钮(例如LeftButt

我可以轻松检查哪个按钮当前处于按下状态或释放状态。例如,要检查LeftButton当前是否已释放,我可以使用:

void mouse_event_handler(object sender, MouseButtonEventArgs e)
{
    if (e.LeftButton == MouseButtonState.Released)
    {
        // left button is released
    }
}
我的问题是:如何确定哪个鼠标按钮(例如LeftButton)最近刚从按下状态更改为释放状态?上述方法将无法确定这一点,因为无论之前释放了哪个按钮(MiddleButton或RightButton),该方法也将为真,即它仅检查当前状态。我不确定C/WPF是否本机支持此功能。我想要像这样的东西:

if (e.LeftButton == MouseButtonState.Just_Released)

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

您可以使用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
}

更多信息:

您可以使用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
}

更多信息:

我认为你的旗帜,可能还有一个背景计时器,是唯一的办法。内置功能没有理由有这种行为,而且它会产生很少使用的开销。好问题+1我认为你的旗帜,可能还有一个背景计时器,是实现这一目标的唯一途径。内置功能没有理由有这种行为,而且它会产生很少使用的开销。好问题+1耶!好发现+1.herohuyongtao,如果这对你有效,一定要把它作为答案。像这样的东西可能很方便。耶!好发现+1.herohuyongtao,如果这对你有效,一定要把它作为答案。像这样的东西可能非常方便。