CustomTaskPane.DockPositionChanged 事件
當使用者變更自訂工作窗格的停駐位置時,或程式碼變更 DockPosition 屬性值時發生。
命名空間: Microsoft.Office.Tools
組件: Microsoft.Office.Tools.Common (在 Microsoft.Office.Tools.Common.dll 中)
語法
'宣告
Event DockPositionChanged As EventHandler
event EventHandler DockPositionChanged
範例
下列程式碼會示範 DockPositionChanged 事件的事件處理常式。 這個事件處理常式會修改工作窗格上 FlowLayoutPanel 的 FlowDirection 屬性,變更控制項在工作窗格上呈現水平或垂直排列。 這個程式碼範例也會假設工作窗格包含名為 MyUserControl 的 UserControl,而且 UserControl 包含名為 FlowPanel 的 FlowLayoutPanel。 這個範例是 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 安全性
- 完全信任立即呼叫者。這個成員無法供部分信任的程式碼使用。如需詳細資訊,請參閱從部分受信任程式碼使用程式庫。