How to get the location of the custom task pane when it is floating?
Locked
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.- Edited byJi.ZhouMSFT, ModeratorWednesday, February 11, 2009 12:48 PM
- Edited byJi.ZhouMSFT, ModeratorSaturday, February 14, 2009 1:05 AM
Answers
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.- Marked As Answer byJi.ZhouMSFT, ModeratorWednesday, February 11, 2009 12:49 PM
All Replies
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.- Marked As Answer byJi.ZhouMSFT, ModeratorWednesday, February 11, 2009 12:49 PM
- 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.


