Visual Studio Developer Center > Visual Studio Forums > Visual Studio Tools for Office > How to get the location of the custom task pane when it is floating?
Ask a questionAsk a question
 

LockedHow to get the location of the custom task pane when it is floating?

Locked

  • Sunday, February 08, 2009 12:35 PMJi.ZhouMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    How to get the location of the custom task pane when it is floating?


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

Answers

All Replies

  • Sunday, February 08, 2009 12:36 PMJi.ZhouMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    VSTO’s custom task pane object does not expose the Left and Top property to tell the location information. But, we have some possible workarounds for this.

    1.    We can get the location information via the Office CommandBar object. This is the simplest solution:

    String ctpName = “Custom Task Pane”;

    this.CustomTaskPanes.Add(new UserControl1(), ctpName).Visible = true;

    this.Application.CommandBars[ctpName].Left

    this.Application.CommandBars[ctpName].Top

     

    2.       We can also get the location information using the Windows API FindWindowW and GetWindowRect. For more detailed information, please refer to the forum discussion:

    http://social.msdn.microsoft.com/forums/en-US/vsto/thread/ed72d66d-6159-49fd-a6e2-ad365f275bb3/  

    (Related forum thread, http://social.msdn.microsoft.com/forums/en-US/vsto/thread/ed72d66d-6159-49fd-a6e2-ad365f275bb3/ )



    For more FAQ about Visual Studio Tools for Office, please see Visual Studio Tools for Office FAQ




    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
  • Wednesday, April 01, 2009 11:59 AMJi.ZhouMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Add VB version codes,

     Dim ctpName As String
     ctpName = "Custom Task Pane"
     Me.CustomTaskPanes.Add(New System.Windows.Forms.UserControl, ctpName).Visible = True
     Me.Application.CommandBars.Item(ctpName).Left
     Me.Application.CommandBars.Item(ctpName).Top

    We have published a VSTO FAQ recently, you can view them from the entry thread http://social.msdn.microsoft.com/Forums/en/vsto/thread/31b1ffbf-117b-4e8f-ad38-71614437df59. If you have any feedbacks or suggestions on this FAQ, please feel free to write us emails to colbertz@microsoft.com.