Action-Klasse (2007 System)

Aktualisiert: November 2007

Stellt eine Visual Studio Tools for Office-Smarttagaktion in einem Microsoft Office Word-Dokument dar.

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

Syntax

<PermissionSetAttribute(SecurityAction.Demand, Name := "FullTrust")> _
Public Class Action _
    Inherits ActionBase

Dim instance As Action
[PermissionSetAttribute(SecurityAction.Demand, Name = "FullTrust")]
public class Action : ActionBase

Hinweise

Aktionen sind die im Kontextmenü eines Smarttags verfügbaren Optionen, wenn ein Smarttag eines bestimmten Typs erkannt wird. Ein Beispiel für eine mögliche Aktion ist "Add name to the Contacts folder" für eine Zeichenfolge des Typs Name der Person. Weitere Informationen über Smarttags in Visual Studio Tools for Office finden Sie unter Smarttagarchitektur.

Beispiele

Im folgenden Codebeispiel wird veranschaulicht, wie ein Smarttag mit einer Aktion erstellt wird. Die Smarttagaktion ändert die Menübeschriftung der Aktion zur Laufzeit und zeigt die Position des erkannten Texts an. Sie können das Beispiel testen, indem Sie die Wörter "term" und "recognize" an verschiedenen Positionen in das Dokument eingeben und anschließend die Smarttagaktion ausführen.

Dieses Beispiel bezieht sich auf eine Anpassung auf Dokumentebene.

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

Vererbungshierarchie

System.Object
  Microsoft.Office.Tools.ActionBase
    Microsoft.Office.Tools.Word.Action

Threadsicherheit

Alle öffentlichen static (Shared in Visual Basic)-Member dieses Typs sind threadsicher. Bei Instanzmembern ist die Threadsicherheit nicht gewährleistet.

Siehe auch

Referenz

Action-Member

Microsoft.Office.Tools.Word-Namespace

SmartTag

Weitere Ressourcen

Smarttagarchitektur

Gewusst wie: Hinzufügen von Smarttags zu Word-Dokumenten

Gewusst wie: Erstellen von Smarttags mit benutzerdefinierten Erkennungen in Word

Exemplarische Vorgehensweise: Erstellen eines Smarttags mit einer Anpassung auf Dokumentebene