You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

VSTO Outlook:如何让自定义任务窗格默认以指定高度展开

解决Outlook自定义任务窗格设置Visible后自动折叠的问题

你当前的自定义任务窗格初始化代码如下:

this.myUserControl = new myUserControl();
this.myCustomTaskPane = Globals.ThisAddIn.CustomTaskPanes.Add(this.myUserControl, Properties.Resources.myText, this.Window);
this.myCustomTaskPane.DockPosition = Microsoft.Office.Core.MsoCTPDockPosition.msoCTPDockPositionTop;
this.myCustomTaskPane.DockPositionRestrict = Microsoft.Office.Core.MsoCTPDockPositionRestrict.msoCTPDockPositionRestrictNoChange;
this.myCustomTaskPane.Height = 80;
this.myCustomTaskPane.Visible = false;

当后续执行this.myCustomTaskPane.Visible = true;时,任务窗格会处于折叠状态,无法自动展开到预设的80高度。这是因为Office的UI引擎在任务窗格隐藏状态下,不会持久化保存高度设置,再次显示时会默认使用折叠状态的尺寸。

可以通过以下两种方式解决:

方法一:显示后重新设置高度

在设置Visible = true之后,再次指定高度值,强制UI引擎应用预设尺寸:

this.myCustomTaskPane.Visible = true;
// 重新设置高度,触发任务窗格展开到指定尺寸
this.myCustomTaskPane.Height = 80;

方法二:初始化时先显式加载尺寸再隐藏

修改初始化代码,先短暂显示任务窗格并设置高度,再将其隐藏,让Office记住这个尺寸参数:

this.myUserControl = new myUserControl();
this.myCustomTaskPane = Globals.ThisAddIn.CustomTaskPanes.Add(this.myUserControl, Properties.Resources.myText, this.Window);
this.myCustomTaskPane.DockPosition = Microsoft.Office.Core.MsoCTPDockPosition.msoCTPDockPositionTop;
this.myCustomTaskPane.DockPositionRestrict = Microsoft.Office.Core.MsoCTPDockPositionRestrict.msoCTPDockPositionRestrictNoChange;

// 先显示任务窗格,确保高度设置被UI引擎接收
this.myCustomTaskPane.Visible = true;
this.myCustomTaskPane.Height = 80;
// 再隐藏,后续显示时会自动使用已保存的高度
this.myCustomTaskPane.Visible = false;

两种方法都能让任务窗格在后续设置Visible = true时,自动展开到80高度,无需手动调整。

内容的提问来源于stack exchange,提问作者Willy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.26 01:27:15