SmartTag 接口

表示使用 Visual Studio 中的 Office 开发工具自定义的 Word 文档中的智能标记。

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

语法

声明
<GuidAttribute("2b90a8e2-4e6c-4c27-bd35-a6ba7b344223")> _
Public Interface SmartTag _
    Inherits SmartTagBase
[GuidAttribute("2b90a8e2-4e6c-4c27-bd35-a6ba7b344223")]
public interface SmartTag : SmartTagBase

SmartTag 类型公开以下成员。

属性

  名称 说明
公共属性 Actions 获取或设置一个由智能标记公开的操作的数组。 此类型或成员只适合在 2007 Microsoft Office system 项目中使用。Office 2010 中已弃用智能标记。
. (继承自 SmartTagBase。)
公共属性 Caption 获取智能标记的名称。 此类型或成员只适合在 2007 Microsoft Office system 项目中使用。Office 2010 中已弃用智能标记。
. (继承自 SmartTagBase。)
公共属性 DefaultExtension 获取此 SmartTag 对象的默认扩展。 此类型或成员只适合在 2007 Microsoft Office system 项目中使用。Office 2010 中已弃用智能标记。
.
公共属性 Expressions 获取智能标记将识别的正则表达式的集合。 此类型或成员只适合在 2007 Microsoft Office system 项目中使用。Office 2010 中已弃用智能标记。
. (继承自 SmartTagBase。)
公共属性 Extension 获取此 SmartTag 对象的自定义扩展。
公共属性 SmartTagType 获取充当智能标记唯一标识符的命名空间。 此类型或成员只适合在 2007 Microsoft Office system 项目中使用。Office 2010 中已弃用智能标记。
. (继承自 SmartTagBase。)
公共属性 Terms 获取智能标记将识别的字符串的集合。 此类型或成员只适合在 2007 Microsoft Office system 项目中使用。Office 2010 中已弃用智能标记。
. (继承自 SmartTagBase。)

页首

方法

  名称 说明
公共方法 Remove 从智能标记中移除正则表达式识别器。 此类型或成员只适合在 2007 Microsoft Office system 项目中使用。Office 2010 中已弃用智能标记。
. (继承自 SmartTagBase。)

页首

备注

若要创建智能标记,请使用 Globals.Factory.CreateSmartTag 方法来创建 SmartTag 对象。

备注

此接口由 Visual Studio Tools for Office Runtime 实现。不应在代码中实现此接口。有关详细信息,请参阅 Visual Studio Tools for Office Runtime 概述

用法

此类型的设计目的是仅用在 Word 2007 的项目中。 智能标记在 Word 2010 中被弃用。

示例

下面的代码示例演示如何创建智能标记。 智能标记操作在运行时修改操作的菜单标题,并显示已识别的文本所在的位置。

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 命名空间