WebBrowser and tab/focus issues

Add-in Express™ Support Service
That's what is more important than anything else

WebBrowser and tab/focus issues
 
Clancy Malcolm


Guest


I have a custom task pane (user control) with a few buttons and a System.Windows.Forms.WebBrowser control. When I show task pane when the user clicks on a ribbon button using:
  this.TaskPanes[0][this.WordApp.ActiveWindow].Visible = true;


The first page loaded in the browser has a username and password inputs. I can't find a way to activate the task pane (give it the focus). I've tried something like:
  ((CJTaskPane)this.TaskPanes[0][this.WordApp.ActiveWindow].Control).Focus();


I've also tried calling the Focus method on one of the buttons on the task pane.

When you click on a button to give the task pane the focus (it's title bar changes color slightly) you can use the tab key to navigate between the buttons and the elements in the browser. However if you don't click on a button and when the document has the focus click on the browser, the task pane does not get the focus and the tab key doesn't work to move from the username to password inputs.

Can you please tell me how to:
1. Give the user name input in the browser control the focus when the task pane is first displayed?
2. Allow the tab key to work for moving between username and password fields?

It seems similar to http://www.add-in-express.com/forum/read.php?FID=5&TID=9869. I have tried their solution of using SendMessageW, but couldn't get it to work.

I have also seen http://www.add-in-express.com/forum/read.php?FID=5&TID=5635 and shows a similar issue, but in my case it is in a task pane so I can't set the parent.

I am using a custom task pane as I need it to work in Word and Outlook 2007+.

Thanks for your help.

Clancy
Posted 14 Sep, 2012 01:08:17 Top
Eugene Astafiev


Guest


Hi Clancy,

Do you use http://www.add-in-express.com/add-in-net/office-task-panes.php or http://msdn.microsoft.com/en-us/library/aa942864%28v=vs.80%29.aspx?

The fact is that the http://www.add-in-express.com/forum/read.php?FID=5&TID=9869 forum thread is related to Advanced Office Task Panes (not Office Task Panes). Anyway, the following code works like a charm on my PC with Office 2010 installed:

private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
   webBrowser1.Focus();
}


The WebBrowser control is focused. I just press the TAB button on my keyboard for moving the focus between the input controls located on the page.

FYI Please pay attention to the fact that you don't release underlying COM objects properly in the code:

this.WordApp.ActiveWindow


The ActiveWindow property of the Application class returns an instance of the Window class which should be released after. You can read more about this in the http://www.add-in-express.com/creating-addins-blog/2008/10/30/releasing-office-objects-net/ article on our technical blog.
Posted 14 Sep, 2012 11:05:51 Top