Action 介面

表示使用 Visual Studio 的 Office 開發工具所自訂之 Word 文件中的智慧標籤動作。

命名空間:  Microsoft.Office.Tools.Word
組件:  Microsoft.Office.Tools.Word (在 Microsoft.Office.Tools.Word.dll 中)

語法

'宣告
<GuidAttribute("1886a0c6-4e1a-4b8f-8304-5143462fe2b6")> _
Public Interface Action _
    Inherits ActionBase
[GuidAttribute("1886a0c6-4e1a-4b8f-8304-5143462fe2b6")]
public interface Action : ActionBase

Action 型別會公開下列成員。

屬性

  名稱 說明
公用屬性 Caption 取得或設定動作名稱,如智慧標籤功能表上所顯示。 這個類型或成員僅適用於 2007 Microsoft Office system 專案。智慧標籤在 Office 2010 中已被取代。
. (繼承自 ActionBase)。

回頁首

事件

  名稱 說明
公用事件 BeforeCaptionShow 在使用者按一下智慧標籤圖示之後,顯示智慧標籤功能表之前發生。 這個類型或成員僅適用於 2007 Microsoft Office system 專案。智慧標籤在 Office 2010 中已被取代。
.
公用事件 Click 在智慧標籤功能表上按一下時發生。 這個類型或成員僅適用於 2007 Microsoft Office system 專案。智慧標籤在 Office 2010 中已被取代。
.

回頁首

備註

動作是指系統在辨認智慧標籤的型別後,出現在智慧標籤捷徑功能表上的可用選項。 若要建立動作,請使用 Globals.Factory.CreateAction 方法建立 Action 物件。

注意事項注意事項

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

使用方式

這個型別僅適用於 Word 2007 專案。 只有在 Word 2010 中已被取代。

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

範例

下列程式碼範例示範如何建立具備動作的智慧標籤。 智慧標籤動作會修改在執行階段時動作的功能表標題,並且顯示所辨認文字的位置。

Private WithEvents displayAddress As Microsoft.Office.Tools.Word.Action

Private Sub AddSmartTag()

    ' Create the smart tag for .NET Framework 4 projects.
    Dim smartTagDemo As Microsoft.Office.Tools.Word.SmartTag = Globals.Factory.CreateSmartTag(
        "www.microsoft.com/Demo#DemoSmartTag",
        "Demonstration Smart Tag")

    ' For .NET Framework 3.5 projects, use the following code to create the smart tag.
    ' Dim smartTagDemo As New  _
    '     Microsoft.Office.Tools.Word.SmartTag( _
    '     "www.microsoft.com/Demo#DemoSmartTag", _
    '     "Demonstration Smart Tag")

    ' Specify the terms to recognize.
    smartTagDemo.Terms.Add("term")
    smartTagDemo.Terms.Add("recognize")

    ' Create the action for .NET Framework 4 projects.
    displayAddress = Globals.Factory.CreateAction("To be replaced")

    ' For .NET Framework 3.5 projects, use the following code to create the action.
    ' displayAddress = New Microsoft.Office.Tools.Word.Action("To be replaced")

    ' Add the action to the smart tag.
    smartTagDemo.Actions = New Microsoft.Office.Tools.Word.Action() { _
            displayAddress}

    ' Add the smart tag.
    Me.VstoSmartTags.Add(smartTagDemo)
End Sub

Private Sub DisplayAddress_BeforeCaptionShow(ByVal sender As Object, _
    ByVal e As Microsoft.Office.Tools.Word.ActionEventArgs) _
    Handles displayAddress.BeforeCaptionShow

    Dim clickedAction As Microsoft.Office.Tools.Word.Action = _
        TryCast(sender, Microsoft.Office.Tools.Word.Action)

    If clickedAction IsNot Nothing Then
        clickedAction.Caption = "Display the location of " & e.Text
    End If
End Sub

Private Sub DisplayAddress_Click(ByVal sender As Object, _
    ByVal e As Microsoft.Office.Tools.Word.ActionEventArgs) _
    Handles displayAddress.Click

    Dim termStart As Integer = e.Range.Start
    Dim termEnd As Integer = e.Range.End
    MsgBox("The recognized text '" & e.Text & _
            "' begins at position " & termStart & _
            " and ends at position " & termEnd)
End Sub
private Microsoft.Office.Tools.Word.Action displayAddress;

private void AddSmartTag()
{
    // Create the smart tag for .NET Framework 4 projects.
    Microsoft.Office.Tools.Word.SmartTag smartTagDemo =
        Globals.Factory.CreateSmartTag(
        "www.microsoft.com/Demo#DemoSmartTag",
        "Demonstration Smart Tag");

    // For .NET Framework 3.5 projects, use the following code to create the smart tag.
    // Microsoft.Office.Tools.Word.SmartTag smartTagDemo =
        // new Microsoft.Office.Tools.Word.SmartTag(
        //     "www.microsoft.com/Demo#DemoSmartTag",
        //     "Demonstration Smart Tag");

    // Specify the terms to recognize.
    smartTagDemo.Terms.Add("term");
    smartTagDemo.Terms.Add("recognize");

    // Create the action for .NET Framework 4 projects.
    displayAddress = Globals.Factory.CreateAction("To be replaced"); 

    // For .NET Framework 3.5 projects, use the following code to create the action.
    // displayAddress = new Microsoft.Office.Tools.Word.Action("To be replaced");

    // Add the action to the smart tag.
    smartTagDemo.Actions = new Microsoft.Office.Tools.Word.Action[] { 
        displayAddress };

    // Add the smart tag.
    this.VstoSmartTags.Add(smartTagDemo);

    displayAddress.BeforeCaptionShow += new
        Microsoft.Office.Tools.Word.BeforeCaptionShowEventHandler(
        displayAddress_BeforeCaptionShow);

    displayAddress.Click += new
        Microsoft.Office.Tools.Word.ActionClickEventHandler(
        displayAddress_Click);
}

void displayAddress_BeforeCaptionShow(object sender,
    Microsoft.Office.Tools.Word.ActionEventArgs e)
{
    Microsoft.Office.Tools.Word.Action clickedAction =
        sender as Microsoft.Office.Tools.Word.Action;

    if (clickedAction != null)
    {
        clickedAction.Caption = "Display the location of " +
            e.Text;
    }
}

void displayAddress_Click(object sender,
    Microsoft.Office.Tools.Word.ActionEventArgs e)
{
    int termStart = e.Range.Start;
    int termEnd = e.Range.End;
    System.Windows.Forms.MessageBox.Show("The recognized text '" + e.Text +
        "' begins at position " + termStart.ToString() +
        " and ends at position " + termEnd.ToString());
}

請參閱

參考

Microsoft.Office.Tools.Word 命名空間

SmartTag

其他資源

Walkthrough: Creating a Smart Tag that Converts Temperatures from Fahrenheit to Celsius