开发者

Is there a way to control the width of the left task pane holding an add-in?

开发者 https://www.devze.com 2023-03-16 22:07 出处:网络
I have an excel 2007 Add-in built with VS开发者_开发百科2010 VSTO library. when i create a new object of the add-in, i also create an excel left task pane, using the following code:

I have an excel 2007 Add-in built with VS开发者_开发百科2010 VSTO library. when i create a new object of the add-in, i also create an excel left task pane, using the following code:

Microsoft.Office.Tools.CustomTaskPane taskPaneAddIn;
MyAddIn addIn;

addIn = new MyAddIn(this.Application);
taskPaneAddIn = this.CustomTaskPanes.Add(addIn, "My AddIn");
taskPaneAddIn.DockPosition = Microsoft.Office.Core.MsoCTPDockPosition.msoCTPDockPositionLeft;
taskPaneAddIn.Width = addIn.Size.Width + 5;

The addIn is a windows user control which has its own dimensions.

The code above seems not to work as the taskPaneAddIn width is always fixed on the excel. the user always has to manually expand the task pane to see the entire width of the control.

Is there any programmable way to set the task pane width?


I think the source of your problem is that when you add the control to the CustomTaskPanes, its Width gets set to zero (I think it has to do with the fact that the control gets docked). To address your problem, you can do the following, and retrieve the width of your control before it is added:

var control = new TaskPaneControl();
var width = control.Width;
var taskPane = CustomTaskPanes.Add(control, "Wide");
taskPane.Width = width;
taskPane.Visible = true;
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号