How can I handle the mouse wheel click event in WPF?

夙愿已清 提交于 2019-12-08 19:21:36

问题


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");
        }
    }

回答1:


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




回答2:


An even easier solution

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



来源:https://stackoverflow.com/questions/517556/how-can-i-handle-the-mouse-wheel-click-event-in-wpf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!