CustomTaskPane.DockPositionChanged 事件 (2007 system)

更新:2007 年 11 月

当用户更改自定义任务窗格的停靠位置时,或者当代码更改 DockPosition 属性的值时发生。

命名空间:  Microsoft.Office.Tools
程序集:  Microsoft.Office.Tools.Common.v9.0(在 Microsoft.Office.Tools.Common.v9.0.dll 中)

语法

声明
Public Event DockPositionChanged As EventHandler
用法
Dim instance As CustomTaskPane
Dim handler As EventHandler

AddHandler instance.DockPositionChanged, handler
public event EventHandler DockPositionChanged

示例

下面的代码示例演示 DockPositionChanged 事件的事件处理程序。此事件处理程序通过修改任务窗格上 FlowLayoutPanelFlowDirection 属性来更改控件在任务窗格上的水平或垂直排列。此代码示例假定任务窗格包含一个名为 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;
        }
    }
}

权限

另请参见

参考

CustomTaskPane 类

CustomTaskPane 成员

Microsoft.Office.Tools 命名空间