none
Excel CustomTaskPane with WebBrowser control - keyboard/focus issues RRS feed

  • Question

  • Hi-
    I have a simple app-level addin for Excel 2007 built using VS 2008 SP1.  It creates a CustomTaskPane (CTP) in which there is a single UserControl (WebBrowserTaskPane) that is filled with a single child control: a System.Windows.Forms.WebBrowser

    The problem is that the active worksheet in Excel gets/keeps keyboard focus so that keystrokes intended for the WebBrowser in the CTP end up in the active cell in the worksheet.  The code for the addin/UserControl is pasted in below, but the summary of how to reproduce the issue is:

    1. ThisAddin_Startup creates an instance of my WebBrowserTaskPane (UserControl), and then calls CustomTaskPanes.Add() to create a new CTP. Then it sets the width of the CTP, makes it Visible, and instructs the embedded WebBrowser control to Navigate to a URL (say http://www.microsoft.com)
    2. The end user sees the default "Book1" workbook open, and the CTP showing the expected web page.
    3. End user clicks somewhere in the web page (not on a link) -- for some pages, this gives focus to the CTP (title goes yellow), and keys typed go to the web page (eg. search box) as expected.
    4. Click back in the worksheet, gives keyboard focus as expected.
    5. Click back in the CTP - focus does not get transferred - it is still in the worksheet. Keys typed end up in the active cell.

    (Note for some web pages eg. www.google.com, I see the bad behavior right away. Ie. at step 3, focus is not transferred to the CTP as expected).

    I have seen this thread:
    http://social.msdn.microsoft.com/Forums/en-US/vsofficetools2008prerelease/thread/4472b96a-bec6-41c5-9f74-2518945922dc/
    which describes a similar issue but that appears to be WPF-specific.

    I'd appreciate any pointers about working around this.  Instructing end-users to press F6 is not going to suffice: they expect to click on the CTP (say in a search text box ) and start typing.

    BTW- in a doc-level solution using the ActionsPane, I do not see this same behavior.
    Thanks-
    -Shaun

    // Addin Code:
        public partial class ThisAddIn
        {
           private WebBrowserTaskPane m_taskPaneControl;
           private CustomTaskPane m_taskPane;
    
            private void ThisAddIn_Startup(object sender, System.EventArgs e)
            {
               m_taskPaneControl = new WebBrowserTaskPane();
               m_taskPane = this.CustomTaskPanes.Add (m_taskPaneControl, "Test Task Pane");
               m_taskPane.Width = 300;
               m_taskPane.Visible = true;
               m_taskPaneControl.NavigateToUrl ("http://www.microsoft.com");
            }
    
            private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
            {
            }
    // . . .
    
    // UserControl code:
       public partial class WebBrowserTaskPane : UserControl
       {
          public WebBrowserTaskPane ()
          {
             InitializeComponent ();
          }
    
          public void NavigateToUrl (string url)
          {
             this.m_webBrowser.Navigate (url);
          }
    
       }
    // . . .
          private void InitializeComponent ()
          {
             this.m_webBrowser = new System.Windows.Forms.WebBrowser ();
             this.SuspendLayout ();
             // 
             // m_webBrowser
             // 
             this.m_webBrowser.Dock = System.Windows.Forms.DockStyle.Fill;
             this.m_webBrowser.Location = new System.Drawing.Point (0, 0);
             this.m_webBrowser.MinimumSize = new System.Drawing.Size (20, 20);
             this.m_webBrowser.Name = "m_webBrowser";
             this.m_webBrowser.Size = new System.Drawing.Size (150, 150);
             this.m_webBrowser.TabIndex = 0;
             // 
             // WebBrowserTaskPane
             // 
             this.AutoScaleDimensions = new System.Drawing.SizeF (6F, 13F);
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
             this.Controls.Add (this.m_webBrowser);
             this.Name = "WebBrowserTaskPane";
             this.ResumeLayout (false);
    
          }
    

    Shaun Logan - Oracle
    Tuesday, December 15, 2009 4:50 PM

Answers

  • Hello, 

    Sorry for delay. I was able to reproduce the issue you are seeing. I have reported a feedback through Visual Studio & .NET Connect site: https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=521465.

    This issue will be routed to the product unit who works on this specific feature area for triage and resolution. I'll paste all responses from the produce unit in this thread. And you also can click the link and add the feedback to your watchlist (you need to log in using your account) so that you can get informed as soon as product units respond. It may be some time before we get response from product unit. Please be patient.

    Best regards,
    Bessie
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by Bessie Zhao Thursday, December 24, 2009 1:56 AM
    Monday, December 21, 2009 6:48 AM

All replies

  • Hello, 

    Sorry for delay. I was able to reproduce the issue you are seeing. I have reported a feedback through Visual Studio & .NET Connect site: https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=521465.

    This issue will be routed to the product unit who works on this specific feature area for triage and resolution. I'll paste all responses from the produce unit in this thread. And you also can click the link and add the feedback to your watchlist (you need to log in using your account) so that you can get informed as soon as product units respond. It may be some time before we get response from product unit. Please be patient.

    Best regards,
    Bessie
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by Bessie Zhao Thursday, December 24, 2009 1:56 AM
    Monday, December 21, 2009 6:48 AM
  • Hey Bessie,

    I've run into this issue as well and have confirmed that it's also a problem in Excel 2010 Beta 2. Is there any update you can provide on this?

    Casey
    • Edited by CaseyMargell Friday, February 19, 2010 6:21 PM Change "Office" to "Excel" since Excel is the only product affected as far as I know
    Friday, February 19, 2010 6:20 PM
  • Putting on my wayback hat here.

    I'm fighting with this issue again. This time in Excel 2013. Any updates? This is a little bit ridiculous.

    Thursday, May 15, 2014 12:14 AM
  • I wanted to start a thread. Then I saw this one on the main page. In Excel 2010 I have the same behavior.

    The cell is not in the edit mode. I can click in to the text box within the browser control. I can select the text in it, copy it and also paste text from the clipboard into the text box using the mouse. But as soon as I use the keyboard the active cell goes into the edit mode and catches all the keystrokes.

    In Outlook, PowerPoint, and Word everything behaves as it is expected.

    This is a really huge showstopper for us. Is there a fix or workaround?

    Monday, May 19, 2014 12:05 PM
  • You know those pieces of code that you write and feel a little bit dirty about? This is how I worked around it.

    Inside of a VisibleChanged event handler on the task pane:

    DispatcherTimer t = new DispatcherTimer() { 
        Interval = TimeSpan.FromMilliseconds(50) 
    };
    
    int tickCount = 0;
    t.Tick += (a, b) =>
    {
        if (tickCount > 0)
        {
            pane.txtDescription.Focus();
            Keyboard.Focus(pane.txtDescription);
            t.Stop();
        }
        else
        {
            SendKeys.Send(" ");
            SendKeys.Send("{ESC}");
        }
    
        tickCount++;
    };
    t.Start();

    Basically I:
    //Create timer
    //First time it fires I send a space (goes into a cell) followed by "ESC"
    //Second time it fires I set focus back on the field in the task pane

    Feel free to ask me any clarifying questions. Hope this helps,

    Casey


    • Edited by CaseyMargell Monday, May 19, 2014 8:43 PM added context of where the code I had provided lives
    Monday, May 19, 2014 5:55 PM
  • This issue is causing me some headaches - exactly as described by Shaun nearly 5 years ago, but using VS2010, Excel 2010.

    Is there still no valid workaround from Microsoft?

    Telling users to hit F6 is not an option.


    Wednesday, July 23, 2014 2:33 PM