简体   繁体   中英

Allow user to zoom with mousewheel using the cefsharp browser

I am running cefsharp/75. I want to turn on zooming with the ctrl key and the mousewheel. My event handler is never triggered. And if you hold ctrl and use the mouse will the screen doesn't move. So something inside the control and handling the event. Is there just a setting I am missing?

I added mouse and keyboard zoom. In init section subscribe for events

cefBrowser.PreviewMouseWheel += CefBrowser_PreviewMouseWheel;
cefBrowser.KeyUp += CefBrowser_KeyUp;

I used PreviewMouseWheel to avoid scrolling during zoom ( e.Handled = true ).

private void CefBrowser_PreviewMouseWheel(object sender, MouseWheelEventArgs e) {

  if (Keyboard.Modifiers != ModifierKeys.Control)
    return;

  if (e.Delta > 0)
    cefBrowser.ZoomInCommand.Execute(null);
  else
    cefBrowser.ZoomOutCommand.Execute(null);
  e.Handled = true;
}

private void CefBrowser_KeyUp(object sender, KeyEventArgs e) {

  if (Keyboard.Modifiers != ModifierKeys.Control)
    return;

  if (e.Key == Key.Add)
    cefBrowser.ZoomInCommand.Execute(null);
  if (e.Key == Key.Subtract)
    cefBrowser.ZoomOutCommand.Execute(null);
  if (e.Key == Key.NumPad0)
    cefBrowser.ZoomLevel = 0;
}

So now cef zooming almost like chrome

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM