Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF: Detect Ctrl+MWheelUp/Down

Tags:

wpf

I can bind to Ctrl+C or Ctrl+LeftClick, but how can I bind to mouse/scroll wheel actions?

I am trying to do something like increase/decrease font size, like in a browser.

I want to set Ctrl+MWheelUp to the increase font size

like image 799
Jiew Meng Avatar asked Sep 01 '10 13:09

Jiew Meng


1 Answers

In constructor add event to PreviewMouseWheel

PreviewMouseWheel += Window_PreviewMouseWheel;

And then in the handler detect the key

private void Window_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
{
    if (Keyboard.Modifiers != ModifierKeys.Control)
        return;

    if (e.Delta > 0)
        ZoomIn();

    else if (e.Delta < 0)
        ZoomOut();
}
like image 130
Lukasz Madon Avatar answered Oct 28 '22 01:10

Lukasz Madon