【问题标题】:Allow user to zoom with mousewheel using the cefsharp browser允许用户使用 cefsharp 浏览器使用鼠标滚轮进行缩放
【发布时间】:2020-01-27 01:55:01
【问题描述】:

我正在运行 cefsharp/75。我想用 ctrl 键和鼠标滚轮打开缩放。我的事件处理程序永远不会被触发。如果您按住 ctrl 并使用鼠标,屏幕将不会移动。所以控制里面的东西和处理事件。我只是缺少一个设置吗?

【问题讨论】:

标签: cefsharp chromium-embedded


【解决方案1】:

我添加了鼠标和键盘缩放。在 init 部分订阅事件

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

我使用PreviewMouseWheel 来避免在缩放期间滚动 (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;
}

所以现在 cef 像 chrome 一样缩放

【讨论】:

  • 这仅适用于 WPF,问题可能与 WinForms 有关。
  • @amaitland 是的,你是对的,我的代码适用于 WPF。我遇到了同样的问题 - 鼠标滚轮事件没有触发。我发现了这个问题。只是想分享一些信息来帮助某人。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-01-11
  • 1970-01-01
  • 2014-04-05
  • 1970-01-01
  • 2017-10-20
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多