问题
I'm building a powerpoint add-in that is going to be based around an embedded browser. For some reason, though, the standard shortcuts don't work. The WebBrowserShortcutsEnabled property is set to true (though I even got as far as trying setting it to false in case I was in backwards world). Stripping it down to the bare bones, my repro steps are:
- Create a new project, selecting the PowerPoint 2013 Add-in project type
- Add a new User Control to the project
- Add a WebBrowser to that control, dragging it from the Toolbox
- Set the URL on that WebBrowser to e.g. google in the properties panel
Add this code to the ThisAddIn_Startup method, so the panel displays immediately:
private void ThisAddIn_Startup(object sender, System.EventArgs e) { var ctrl = new UserControl1(); var ctp = this.CustomTaskPanes.Add(ctrl, "test"); ctp.Visible = true; }
Typing in the WebBrowser inside PowerPoint works fine, but Ctrl+X/C/V, Del, Tab etc. all have no effect.
I've tried overriding the OnKeyPress method on the web browser, as well as adding a PreviewKeyDownEventHandler, but breakpoints in both of those methods never got hit. I've also verified that WebBrowserShortcutsEnabled is still true at run-time and hasn't somehow been changed.
I'm beginning to suspect that it might be an environment issue, but I'm at a loss as to what might the root cause. I'm running Windows 8.1, VS 2012 and PowerPoint 2013, targeting .NET 4.5. I also tried installing the same basic plugin on PowerPoint 2010 on Windows 7 with the same result.
Has anyone got any insight into what might be going wrong for me?
Thanks
回答1:
It would appear that putting the Web Browser inside a Windows Form, and displaying it as a modal window, rather than using a Custom Task Pane makes the shortcuts work as expected.
来源:https://stackoverflow.com/questions/19539369/webbrowser-shortcuts-not-working-in-powerpoint-add-in-but-webbrowsershortcuts