SmartTag Interface

Represents a smart tag in a Word document that is customized by using the Office development tools in Visual Studio.

Namespace:  Microsoft.Office.Tools.Word
Assembly:  Microsoft.Office.Tools.Word (in Microsoft.Office.Tools.Word.dll)

Syntax

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

The SmartTag type exposes the following members.

Properties

  Name Description
Public property Actions Gets or sets an array of actions that are exposed by the smart tag. This type or member is intended to be used only in projects for the 2007 Microsoft Office system. Smart tags are deprecated in Office 2010.
. (Inherited from SmartTagBase.)
Public property Caption Gets the name of the smart tag. This type or member is intended to be used only in projects for the 2007 Microsoft Office system. Smart tags are deprecated in Office 2010.
. (Inherited from SmartTagBase.)
Public property DefaultExtension Gets the default extension for this SmartTag object. This type or member is intended to be used only in projects for the 2007 Microsoft Office system. Smart tags are deprecated in Office 2010.
.
Public property Expressions Gets the collection of regular expressions that the smart tag will recognize. This type or member is intended to be used only in projects for the 2007 Microsoft Office system. Smart tags are deprecated in Office 2010.
. (Inherited from SmartTagBase.)
Public property Extension Gets a custom extension for this SmartTag object.
Public property SmartTagType Gets a namespace that acts as a unique identifier for the smart tag. This type or member is intended to be used only in projects for the 2007 Microsoft Office system. Smart tags are deprecated in Office 2010.
. (Inherited from SmartTagBase.)
Public property Terms Gets the collection of string literals that the smart tag will recognize. This type or member is intended to be used only in projects for the 2007 Microsoft Office system. Smart tags are deprecated in Office 2010.
. (Inherited from SmartTagBase.)

Top

Methods

  Name Description
Public method Remove Removes a regular expression recognizer from the smart tag. This type or member is intended to be used only in projects for the 2007 Microsoft Office system. Smart tags are deprecated in Office 2010.
. (Inherited from SmartTagBase.)

Top

Remarks

To create smart tag, use the Globals.Factory.CreateSmartTag method to create a SmartTag object.

Note

This interface is implemented by the Visual Studio Tools for Office runtime. It is not intended to be implemented in your code. For more information, see Visual Studio Tools for Office Runtime Overview.

Usage

This type is intended to be used only in projects for Word 2007. Smart tags are deprecated in Word 2010.

Examples

The following code example demonstrates how to create a smart tag. The smart tag action modifies the menu caption of the action at run time and displays the location of the text that was recognized.

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());
}

See Also

Reference

Microsoft.Office.Tools.Word Namespace