本文為機器翻譯文章。如需檢視英文版,請選取 [原文] 核取方塊。您也可以將滑鼠指標移到文字上,即可在快顯視窗顯示英文原文。
譯文
原文

CustomTaskPane 介面

 

代表 Microsoft Office 應用程式中的自訂工作窗格。

命名空間:   Microsoft.Office.Tools
組件:  Microsoft.Office.Tools.Common (於 Microsoft.Office.Tools.Common.dll)

[GuidAttribute("881b42fd-484d-4494-8500-779de4e4aac1")]
public interface CustomTaskPane : IDisposable

名稱描述
System_CAPS_pubpropertyControl

取得 UserControl ,提供使用者介面的自訂工作窗格。

System_CAPS_pubpropertyDockPosition

取得或設定值,指定自訂工作窗格所在位置相對於應用程式視窗。

System_CAPS_pubpropertyDockPositionRestrict

取得或設定值,這個值,可防止自訂工作窗格停駐在指定的位置。

System_CAPS_pubpropertyHeight

取得或設定自訂工作窗格的高度,以點為單位。

System_CAPS_pubpropertyTitle

取得自訂工作窗格的標題。

System_CAPS_pubpropertyVisible

取得或設定值,指定自訂工作窗格是否可見。

System_CAPS_pubpropertyWidth

取得或設定自訂工作窗格的寬度,以點為單位。

System_CAPS_pubpropertyWindow

取得自訂工作窗格與其相關聯的文件視窗。

名稱描述
System_CAPS_pubmethodDispose()

(繼承自 IDisposable。)

名稱描述
System_CAPS_pubeventDockPositionChanged

發生於使用者變更停駐位置的自訂工作窗格中,或是當程式碼變更的值 DockPosition 屬性。

System_CAPS_pubeventVisibleChanged

發生於使用者顯示或關閉自訂工作窗格中,或是當程式碼變更的值 Visible 屬性。

Use a T:Microsoft.Office.Tools.CustomTaskPane object in an application-level add-in to modify a custom task pane, or to respond when the location or visibility of the custom task pane changes. Task panes are user interface panels that are typically docked to one side of an application window. For information about how to create custom task panes, see Custom Task Pane Overview.

To control the size or location of the custom task pane, you can use properties such as P:Microsoft.Office.Tools.CustomTaskPane.Height, P:Microsoft.Office.Tools.CustomTaskPane.Width, and P:Microsoft.Office.Tools.CustomTaskPane.Visible.

To respond when the custom task pane moves or changes visibility, you can handle the E:Microsoft.Office.Tools.CustomTaskPane.DockPositionChanged and E:Microsoft.Office.Tools.CustomTaskPane.VisibleChanged events.

System_CAPS_note注意

這個介面是由 Visual Studio Tools for Office Runtime 實作, 並不能實作於您的程式碼中。 如需詳細資訊,請參閱Visual Studio Tools for Office Runtime 概觀

本文件說明此類型的版本,其會用在目標為 .NET Framework 4 或更新版本的 Office 專案中。 在以 .NET Framework 3.5 為目標的專案中,此類型可能會有不同的成員,而為此類型提供的程式碼範例可能無法運作。 如需此類型在以 .NET Framework 3.5 為目標之專案中的相關文件,請參閱下列 Visual Studio 2008 文件中的參考章節:http://go.microsoft.com/fwlink/?LinkId=160658

The following code example demonstrates how to create a custom task pane by using the M:Microsoft.Office.Tools.CustomTaskPaneCollection.Add(System.Windows.Forms.UserControl,System.String) method. The example uses properties of the T:Microsoft.Office.Tools.CustomTaskPane object to set the default appearance of the custom task pane, and it defines an event handler for the E:Microsoft.Office.Tools.CustomTaskPane.DockPositionChanged event. To compile this example, copy the code into the ThisAddIn class in an add-in project for an application that supports custom task panes. Replace the default ThisAddIn_Startup method in the ThisAddIn class with the ThisAddIn_Startup method in this example. This example also assumes that the project contains a T:System.Windows.Forms.UserControl named MyUserControl, and the T:System.Windows.Forms.UserControl contains a T:System.Windows.Forms.FlowLayoutPanel named FlowPanel.

private MyUserControl myUserControl1;
private Microsoft.Office.Tools.CustomTaskPane myCustomTaskPane;

private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
    myUserControl1 = new MyUserControl();
    myCustomTaskPane = this.CustomTaskPanes.Add(myUserControl1,
        "New Task Pane");

    myCustomTaskPane.DockPosition =
        Office.MsoCTPDockPosition.msoCTPDockPositionFloating;
    myCustomTaskPane.Height = 500;
    myCustomTaskPane.Width = 500;

    myCustomTaskPane.DockPosition =
        Office.MsoCTPDockPosition.msoCTPDockPositionRight;
    myCustomTaskPane.Width = 300;

    myCustomTaskPane.Visible = true;
    myCustomTaskPane.DockPositionChanged +=
        new EventHandler(myCustomTaskPane_DockPositionChanged);
}

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;
        }
    }
}
回到頁首
顯示: