Action Class (2007 System)
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.v9.0 (in Microsoft.Office.Tools.Word.v9.0.dll)
Syntax
'Declaration
<PermissionSetAttribute(SecurityAction.Demand, Name := "FullTrust")> _
Public Class Action _
Inherits ActionBase
'Usage
Dim instance As Action
[PermissionSetAttribute(SecurityAction.Demand, Name = "FullTrust")]
public class Action : ActionBase
[PermissionSetAttribute(SecurityAction::Demand, Name = L"FullTrust")]
public ref class Action : public ActionBase
public class Action extends ActionBase
Remarks
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.
Examples
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.
This example is for a document-level customization.
Private 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.
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()
{
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.
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());
}
Inheritance Hierarchy
System.Object
Microsoft.Office.Tools.ActionBase
Microsoft.Office.Tools.Word.Action
Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
See Also
Reference
Microsoft.Office.Tools.Word Namespace
Other Resources
How to: Add Smart Tags to Word Documents
How to: Create Smart Tags With Custom Recognizers in Word
Walkthrough: Creating a Smart Tag by Using a Document-Level Customization