none
Seting position of a floating Custome Task Pane RRS feed

  • Question

  • Hi,

    I have a VSTO application and I am working with Excel. Now am opening a custome task pane and setting it's position as 

    msoCTPDockPositionFloating.

    But how can I set the position of that.

    Monday, May 28, 2012 11:35 AM

Answers

  • Hi Anupam

    The custom task pane is "contained" in an Office CommandBar object; you need to grab hold of and manipulate that. For example

                Office.CommandBar cb = Globals.ThisAddIn.Application.CommandBars["Task Pane"];
    cb.Left = 200;
    cb.Top = 200;


    Cindy Meister, VSTO/Word MVP

    Monday, May 28, 2012 2:43 PM
    Moderator

All replies

  • Hi Anupam

    The custom task pane is "contained" in an Office CommandBar object; you need to grab hold of and manipulate that. For example

                Office.CommandBar cb = Globals.ThisAddIn.Application.CommandBars["Task Pane"];
    cb.Left = 200;
    cb.Top = 200;


    Cindy Meister, VSTO/Word MVP

    Monday, May 28, 2012 2:43 PM
    Moderator
  • Hi Cindy,

    Thanks for your reply. However when I tried to set the Left and Top property(i.e. cb.Left/cb.Top) it throws the following exception

    Error HRESULT E_FAIL has been returned from a call to a COM component.

    Tuesday, May 29, 2012 6:43 AM
  • I tried it yesterday, before posting - the code is from my test project. So I know it works.

    Please tell us the version of Excel involved and show us the code that's triggering the message.


    Cindy Meister, VSTO/Word MVP

    Tuesday, May 29, 2012 4:52 PM
    Moderator
  • I am using Excel 2010 and VS2010.

    On click of a button I am programmatically building the task pane and after I build all the controls in it I am writing the following lines.

    _popup.DockPosition = Microsoft.Office.Core.MsoCTPDockPosition.msoCTPDockPositionFloating;

    _popup.Visible = true;
    _popup.Height = 180;
    _popup.Width = 450;

    Microsoft.Office.Core.CommandBar cb = Globals.PRPAddIn.Application.CommandBars[_popup.Title];
    cb.Left = 200;
    cb.Top = 200;

    cb.Left/cb.Top throws the following exception

    Error HRESULT E_FAIL has been returned from a call to a COM component.

    Wednesday, May 30, 2012 6:32 AM
  • Try changing this line to use ThisAddin, not PRPAddIN:

    Microsoft.Office.Core.CommandBar cb = Globals.PRPAddIn.Application.CommandBars[_popup.Title];

    Globals.ThisAddin is your VSTO add-in project class. VSTO knows how to work with that, but not with a project name the developer gives to an add-in.


    Cindy Meister, VSTO/Word MVP

    Wednesday, May 30, 2012 4:43 PM
    Moderator
  • Hi,

      myXceleratePane = this.CustomTaskPanes.Add(XcelerateControl, "Xcelerate");
                myXceleratePane.Visible = true;
                myXceleratePane.DockPosition = Microsoft.Office.Core.MsoCTPDockPosition.msoCTPDockPositionFloating;
                myXceleratePane.DockPositionRestrict = Microsoft.Office.Core.MsoCTPDockPositionRestrict.msoCTPDockPositionRestrictNone;
                
                
                ((Microsoft.Office.Interop.Excel.Window)(myXceleratePane.Window)).WindowState = Excel.XlWindowState.xlMinimized;
                
              
                myXceleratePane.Height = 800;
                myXceleratePane.Width = 800;         
                Office.CommandBar cb = Globals.ThisAddIn.Application.CommandBars[myXceleratePane.Title];
                cb.Left = 0;
                cb.Top = 0;

    cb.Left/cb.Top throws the following exception

    Error HRESULT E_FAIL has been returned from a call to a COM component.

    Friday, July 26, 2013 4:15 PM
  • I get the same result with essentially the same code:  Error HRESULT E_FAIL has been returned from a call to a COM component.  Consensus among other forums is that the only way to do this is with a Windows API.  I would classify this issue as a bug.
    Monday, September 9, 2013 2:01 AM