0

I have a web browser control in a custom task pane control (User Control) and I open it as a sidebar as soon as my Outlook opens (I have created it as an Outlook Addin using Visual Studio 2013). The web browser control has a login form inside it and I would like to place focus on an input control in my web browser control as soon as Outlook opens. I have tried several tricks like placing focus on the custom user control and then placing focus on the input control after the form has loaded but it doesn't place focus on it. Also I have been trying to allow the use of Tab and Delete keys to work inside the web browser control so that I can tab to other controls and play with it like we would do it on a normal browser window. Kindly let me know how I can achieve this as I am out of ideas.

Cheers.

Neophile
  • 5,660
  • 14
  • 61
  • 107
  • This is a known issue with browser controls embedded in Outlook. Consider using another controls for displaying the login form or use Windows API functions for setting hooks. – Eugene Astafiev Apr 28 '15 at 13:54
  • Can you recommend another way of achieving the same instead of browser control? I have a mobile website that I am trying to access in Outlook and I have hosted it on a server where I am accessing it from and the only way I could find was using a web browser control. Do you have any other recommendations? – Neophile Apr 28 '15 at 14:14
  • I believe you can create REST APIs and use them instead. – Eugene Astafiev Apr 28 '15 at 14:39
  • That would be to communicate with the mobile app right? What if I would like some email information to be read from an email directly onto that mobile app? something like that: https://vimeo.com/95753825 – Neophile Apr 28 '15 at 14:47
  • If someone else is looking for a solution, that helped in my case: [DEL and BACKSPACE keys get eaten from WebBrowser](https://stackoverflow.com/a/44246006/6267940) – STARSCrazy Oct 15 '19 at 13:36

3 Answers3

1

Try to use the Excel WebBrowser Control instead of the System.Windows.Forms WebBrowser; it handles special key forwarding as TAB, DEL, CTRL+V, etc.

For that change the WebBrowser contructor from

new System.Windows.Forms.WebBrowser();

to

new Microsoft.Office.Tools.Excel.Controls.WebBrowser();  

You would need to add references to your project: Project/Add Referernce/Extensions select Microsoft.Tools.Outlook & Microsoft.Tools.Outlook.v4.0.Utilities

Doc: https://msdn.microsoft.com/en-us/library/microsoft.office.tools.excel.controls.webbrowser.aspx

bateast
  • 11
  • 2
0

You can only do that if you install a Windows hook (SetWindowsHookExW(WH_GETMESSAGE, YourHookProc, 0, GetCurrentThreadId()) and in the hook proc detect that messages are supposed to go to your browser, and redirect them accordingly.

Dmitry Streblechenko
  • 62,942
  • 4
  • 53
  • 78
  • Thanks for your answer. Can you please help me with this with examples if possible? I am really stuck with this. – Neophile Apr 28 '15 at 13:54
  • I cannot post the code as it is a part of a commercial product, but I'd be happy to answer your questions. – Dmitry Streblechenko Apr 28 '15 at 14:01
  • For starters: How can I install windows hook? – Neophile Apr 28 '15 at 14:16
  • See [Using shortcut keys to call a function in an Office Add-in](http://blogs.msdn.com/b/vsod/archive/2010/04/09/using-shortcut-keys-to-call-a-function-in-an-office-add-in.aspx) – Eugene Astafiev Apr 28 '15 at 14:41
  • Ok basically I did get the focus to work on the usercontrol but it only works when there is a button (for eg) on the user control and then I can toggle from the user control's button to my web browser control. Any suggestions on how I can set the focus to my webbrowser control onload of the usercontrol? – Neophile May 07 '15 at 11:43
  • You really need to post the relevant snippets of your code. – Dmitry Streblechenko May 07 '15 at 13:36
0

It works partially this way but not 100%. First I had to set the TabStop property to True for my webbrowser control and then just set the focus once the document was loaded and that was it. The tab, delete, backspace keys all ran properly.

Private Sub CustomTaskPane_Load(sender As Object, e As EventArgs) Handles Me.Load
        TestWebBrowser.Size = New Drawing.Size(Me.Width, Me.Height)

        Me.Focus()

        TestWebBrowser.Navigate(url)

        WaitForPageLoad()

        TestWebBrowser.TabIndex = 0
        TestWebBrowser.TabStop = True
    End Sub

Private Sub TestWebBrowser_DocumentCompleted(sender As Object, e As Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles TestWebBrowser.DocumentCompleted

        ' Now set the focus on the Web Browser Control
        TestWebBrowser.Focus()
End Sub
Neophile
  • 5,660
  • 14
  • 61
  • 107