CustomTaskPane.Control 属性
获取提供自定义任务窗格用户界面的 UserControl。
命名空间: Microsoft.Office.Tools
程序集: Microsoft.Office.Tools.Common(在 Microsoft.Office.Tools.Common.dll 中)
语法
声明
ReadOnly Property Control As UserControl
Get
UserControl Control { get; }
属性值
类型:System.Windows.Forms.UserControl
提供自定义任务窗格用户界面的 UserControl。
异常
异常 | 条件 |
---|---|
ObjectDisposedException | 已调用 CustomTaskPane 的 Dispose() 方法。 |
备注
此属性返回用于创建自定义任务窗格的 UserControl。 有关更多信息,请参见 自定义任务窗格概述。
示例
下面的代码示例使用 Control 属性在 DockPositionChanged 事件的事件处理程序中修改任务窗格上的 UserControl 的大小。 此代码示例摘自为 CustomTaskPane 提供的一个更大的示例。
Private Sub myCustomTaskPane_DockPositionChanged(ByVal sender As Object, _
ByVal e As EventArgs) Handles myCustomTaskPane.DockPositionChanged
Dim taskPane As Microsoft.Office.Tools.CustomTaskPane = _
TryCast(sender, Microsoft.Office.Tools.CustomTaskPane)
If taskPane IsNot Nothing Then
' Adjust sizes of user control and flow panel to fit current task pane size.
Dim userControl As MyUserControl = TryCast(taskPane.Control, MyUserControl)
Dim paneSize As System.Drawing.Size = _
New System.Drawing.Size(taskPane.Width, taskPane.Height)
userControl.Size = paneSize
userControl.FlowPanel.Size = paneSize
' Adjust flow direction of controls on the task pane.
If taskPane.DockPosition = _
Office.MsoCTPDockPosition.msoCTPDockPositionTop Or _
taskPane.DockPosition = _
Office.MsoCTPDockPosition.msoCTPDockPositionBottom Then
userControl.FlowPanel.FlowDirection = _
System.Windows.Forms.FlowDirection.LeftToRight
Else
userControl.FlowPanel.FlowDirection = _
System.Windows.Forms.FlowDirection.TopDown
End If
End If
End Sub
private void myCustomTaskPane_DockPositionChanged(object sender, EventArgs e)
{
Microsoft.Office.Tools.CustomTaskPane taskPane =
sender as Microsoft.Office.Tools.CustomTaskPane;
if (taskPane != null)
{
// Adjust sizes of user control and flow panel to fit current task pane size.
MyUserControl userControl = taskPane.Control as MyUserControl;
System.Drawing.Size paneSize = new System.Drawing.Size(taskPane.Width, taskPane.Height);
userControl.Size = paneSize;
userControl.FlowPanel.Size = paneSize;
// Adjust flow direction of controls on the task pane.
if (taskPane.DockPosition ==
Office.MsoCTPDockPosition.msoCTPDockPositionTop ||
taskPane.DockPosition ==
Office.MsoCTPDockPosition.msoCTPDockPositionBottom)
{
userControl.FlowPanel.FlowDirection =
System.Windows.Forms.FlowDirection.LeftToRight;
}
else
{
userControl.FlowPanel.FlowDirection =
System.Windows.Forms.FlowDirection.TopDown;
}
}
}
.NET Framework 安全性
- 对直接调用方的完全信任。此成员不能由部分信任的代码使用。有关更多信息,请参见通过部分受信任的代码使用库。