I am having this exact issue https://social.msdn.microsoft.com/Forums/vstudio/en-US/e417e686-032c-4324-b778-fef66c7687cd/excel-customtaskpane-with-webbrowser-control-keyboardfocus-issues?forum=vsto
Also mentioned here https://connect.microsoft.com/VisualStudio/feedback/details/521465/the-focus-issue-between-excel-cells-and-excel-customtaskpane-with-webbrowser-control
I am writing an Excel 2010 plugin using Visual Studio Professional 2013. I've created a simple CustomTaskPane with a System.Windows.Forms.WebBrowser child filing it. The plugin works just fine and I am able to navigate inside the webbrowser by click and change the state of checkboxes.
When I click on an input textbox I get focus and I see the cursor blinking, but when I start typing the text is sent to Excel and written into a cell instead of the textbox inside the browser.
I add the custom taskpane when the ribbon loads.
private void Ribbon_Load(object sender, RibbonUIEventArgs e)
{
TaskPaneView taskPaneView = new TaskPaneView();
Microsoft.Office.Tools.CustomTaskPane myTaskPane = Globals.ThisAddIn.CustomTaskPanes.Add(taskPaneView, "Title");
myTaskPane.Visible = true;
}
When I click on the textbox then hit F6
it works correctly. The customtaskpane header darkens slightly and text is captured in the textbox.
How can i fix this issue so that when I click on the input textbox the text goes into the box instead of Excel?
EDIT: Ok, I did some more testing. If I add events on my TaskPaneView to track mouse enter and click they work, but only if I remove the web browser child. Meaning the web browser is somehow blocking these events and preventing the TaskPaneView from understanding it has focus. If I also added a textbox form control into the TaskPaneView along side the browser, the textbox works totally fine and the TaskPaneView understands it has focus and then the input text field inside the browser then starts works. If I call the focus method directly on the web browser, the TaskPaneView understands it has focus and everything works perfectly. So clearly the issue isn't really with the keyboard, but instead an issue of the TaskPaneView not being told it has focus when the browser is clicked on so the keystrokes go to the wrong area. If I can find a way to make TaskPaneView understand it has focus everythign should work.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…