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

Posts: 9
Joined: 2012-08-05
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:

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 a previous post with a ListView control. I have tried their solution of using SendMessageW, but couldn't get it to work.

I have also seen another posts wh ere the WebBrowser is in a form 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.

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

Add-in Express team

Posts: 8540
Joined: 2007-07-25
Hi Clancy,

Do you use Advanced Office Task Panes or Custom Office Task Panes?

The fact is that the mentioned above 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)

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:


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 When to release COM objects in Office add-ins developed in .NET article on our technical blog.
.NET, Extended MAPI, Windows Phone & RT
Posted 14 Sep, 2012 11:05:51 Top