c# - Excel CustomTaskPane with WebBrowser control - keyboard/focus issues -


i having 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 writing excel 2010 plugin using visual studio professional 2013. i've created simple customtaskpane system.windows.forms.webbrowser child filing it. plugin works fine , able navigate inside webbrowser click , change state of checkboxes.

enter image description here

when click on input textbox focus , see cursor blinking, when start typing text sent excel , written cell instead of textbox inside browser.

i add custom taskpane when 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 click on textbox hit f6 works correctly. customtaskpane header darkens , text captured in textbox.

how can fix issue when click on input textbox text goes box instead of excel?

edit: ok, did more testing. if add events on taskpaneview track mouse enter , click work, if remove web browser child. meaning web browser somehow blocking these events , preventing taskpaneview understanding has focus. if added textbox form control taskpaneview along side browser, textbox works totally fine , taskpaneview understands has focus , input text field inside browser starts works. if call focus method directly on web browser, taskpaneview understands has focus , works perfectly. issue isn't keyboard, instead issue of taskpaneview not being told has focus when browser clicked on keystrokes go wrong area. if can find way make taskpaneview understand has focus everythign should work.

ok able fix issue using following code

protected override void wndproc(ref message m) {   if(m.msg == 528 && !this.focused)   {     this.focus();   }   base.wndproc(ref m); } 

i added function taskpaneview usercontrol webbrowser child. don't have deep understanding of why or how works, think what's happening i'm intercepting wndproc low-level function process messages sent window. use check see if message 528, think means notifyparent. don't know if message should listening for, seems work.

once have right message message check see if taskpaneview has focus , if not, give focus focus() function. did testing earlier showed if manually invoked focus on taskpaneview worked fine. if don't have focus, manually request focus , good.

i appreciate if can provide more detailed explaination why works can understand better, @ least solved problem. jeremy thompson getting me thinking issue in new way.


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -