开发者

WPF: Detect Ctrl+MWheelUp/Down

开发者 https://www.devze.com 2023-01-14 15:53 出处:网络
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 f开发者_如何学Cont size, like in a browser.

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 f开发者_如何学Cont size, like in a browser.

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


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();
}
0

精彩评论

暂无评论...
验证码 换一张
取 消