Click to Rate and Give Feedback
MSDN
MSDN Library
Visual Studio 2005
Visual Studio
Reference
Action Class

  Switch on low bandwidth view
This page is specific to
Microsoft Visual Studio 2005/.NET Framework 2.0

Other versions are also available for the following:
Word Object Model Reference (Visual Studio Tools for Office)
Action Class

Represents a Visual Studio Tools for Office smart tag action in a Microsoft Office Word document.

Namespace: Microsoft.Office.Tools.Word
Assembly: Microsoft.Office.Tools.Word (in microsoft.office.tools.word.dll)

Visual Basic (Declaration)
Public Class Action
	Inherits ActionBase
Visual Basic (Usage)
Dim instance As Action
C#
public class Action : ActionBase

Actions are the choices available on the smart tag shortcut menu when a smart tag of a certain type is recognized. An example of a possible action is "Add name to the Contacts folder" for a string of type Person's Name. For more information about smart tags in Visual Studio Tools for Office, see Smart Tags Architecture.

The following code example demonstrates how to create a smart tag with an action. The smart tag action modifies the menu caption of the action at run time and displays the location of the text that was recognized. To test the example, type the words "term" and "recognize" in different places in the document, and then try the smart tag action.

Visual Basic
#Region "Smart Tag Example"

WithEvents DisplayAddress As Microsoft.Office.Tools.Word.Action

Private Sub AddSmartTag()
    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.
    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 to the document.
    Me.VstoSmartTags.Add(SmartTagDemo)
End Sub

Sub OpenMessageBox_BeforeCaptionShow(ByVal sender As Object, _
    ByVal e As Microsoft.Office.Tools.Word.ActionEventArgs) _
    Handles DisplayAddress.BeforeCaptionShow

    DisplayAddress.Caption = "Display the location of " & _
            e.Text
End Sub

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

#End Region
C#
#region Smart Tag Example

private Microsoft.Office.Tools.Word.Action DisplayAddress;

private void AddSmartTag()
{
    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.
    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 to the document.
    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)
{
    DisplayAddress.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;
    MessageBox.Show("The recognized text '" + e.Text +
        "' begins at position " + termStart.ToString() +
        " and ends at position " + termEnd.ToString());
}

#endregion
System.Object
   Microsoft.Office.Tools.ActionBase
    Microsoft.Office.Tools.Word.Action
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker