开发者

WPF: Detect Ctrl+MWheelUp/Down

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜