我运行的是cefsharp/75。我想用ctrl键和鼠标滚轮打开缩放功能。我的事件处理程序从不被触发。如果你按住ctrl键并使用鼠标,屏幕就不会移动。所以在控件内部的一些东西和处理事件。有没有我遗漏的场景?
发布于 2021-02-23 04:24:11
我添加了鼠标和键盘缩放。在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一样。
https://stackoverflow.com/questions/58122685
复制相似问题