How can I handle the mouse wheel click event in WP

2019-06-17 01:39发布

I want to close a tab in my tab control when the mouse wheel is clicked. How can I capture this event in WPF?

EDIT: Here's the code:

private void tabMain_MouseDown(object sender, MouseButtonEventArgs e)
    {
        if(e.ChangedButton == MouseButton.Middle && e.ButtonState == MouseButtonState.Pressed)
        {
            MessageBox.Show("Middle button clicked");
        }
    }

2条回答
你好瞎i
2楼-- · 2019-06-17 02:01

Mousewheel is actually the MiddleButton, So the condition for Wheel click on a MouseDown event is ChangedButton == Middle && ButtonState == Pressed

查看更多
何必那么认真
3楼-- · 2019-06-17 02:05

An even easier solution

if (e.MiddleButton) { MessageBox.Show("Middle button clicked"); }

查看更多
登录 后发表回答