views:

417

answers:

4

In WPF / C#, there are events on MouseRightButtonDown and MouseLeftButtonDown, but what about the center mouse button?

Is the Center Mouse button down/up e.g. events in WPF forgotten?

How can I check if the center button is clicked or released?

+4  A: 

Use the MouseDown/MouseUp event and check the MouseButtonEventArgs:

private void control_MouseDown(object sender, MouseButtonEventArgs e)
{
    if (e.ChangedButton == MouseButton.Middle)
    {

    }
}
Zenuka
Wow, great! That was an easy one.Thanks
code-zoop
A: 

Use the MouseDown and MouseUp events:

You should use the MouseDown event and check the MiddleButton state in the event arguments.

ChrisF
A: 

you can handle MouseDown event and in event handler you can check which Mouse Button was pressed by using

if(e.ChangedButton == System.Windows.Input.MouseButton.Middle)
{
.....
}
viky
A: 

I do not think there is a direct event handler defined for Up or Down events. The only thing we could do is handle the MouseDown event and check the MiddleButton state like so,

void Window1_MouseDown(object sender, MouseButtonEventArgs e)
    {
        MessageBox.Show(e.MiddleButton.ToString());
    }
theraneman