Action-Schnittstelle

Stellt eine Smarttagaktion in einem Word-Dokument dar, die mit den Office-Entwicklungstools in Visual Studio angepasst wurde.

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

Syntax

'Declaration
<GuidAttribute("1886a0c6-4e1a-4b8f-8304-5143462fe2b6")> _
Public Interface Action _
    Inherits ActionBase
[GuidAttribute("1886a0c6-4e1a-4b8f-8304-5143462fe2b6")]
public interface Action : ActionBase

Der Action-Typ macht die folgenden Member verfügbar.

Eigenschaften

  Name Beschreibung
Öffentliche Eigenschaft Caption Ruft den Namen der Aktion ab, wie dieser im Smarttagmenü angezeigt wird, oder legt diesen Namen fest. (Von ActionBase geerbt.)

Zum Seitenanfang

Ereignisse

  Name Beschreibung
Öffentliches Ereignis BeforeCaptionShow Wird ausgelöst, nachdem der Benutzer auf das Smarttagsymbol geklickt hat und bevor das Smarttagmenü angezeigt wird.
Öffentliches Ereignis Click Wird ausgelöst, wenn im Smarttagmenü auf die Aktion geklickt wird.

Zum Seitenanfang

Hinweise

Aktionen sind die im Kontextmenü eines Smarttags verfügbaren Optionen, wenn ein Smarttag eines bestimmten Typs erkannt wird. Um eine Aktion zu erstellen, verwenden Sie die Globals.Factory.CreateAction-Methode zum Erstellen eines Action-Objekts. Weitere Informationen finden Sie unter Smarttagarchitektur.

Tipp

Diese Schnittstelle wird von der Visual Studio Tools for Office-Laufzeit implementiert. Es ist nicht vorgesehen, dass der Typ direkt vom Code implementiert wird. Weitere Informationen finden Sie unter Übersicht über die Visual Studio Tools for Office-Laufzeit.

Verwendung

Dieser Typ ist gedacht dazu, nur in Projekten für Word 2007 verwendet zu werden. Smarttags sind in Word 2010 veraltet. Weitere Informationen finden Sie unter Übersicht über Smarttags.

In dieser Dokumentation wird die Version dieses Typs beschrieben, der in Office-Projekten mit der Zielversion .NET Framework 4 verwendet wird. In Projekten mit der Zielversion .NET Framework 3.5 verfügt dieser Typ möglicherweise über unterschiedliche Member und die für diesen Typ bereitgestellten Codebeispiele funktionieren möglicherweise nicht. Dokumentation zu diesem Typ in Projekten mit der Zielversion .NET Framework 3.5 finden Sie im folgenden Verweisabschnitt in der Visual Studio 2008-Dokumentation: https://go.microsoft.com/fwlink/?LinkId=160658.

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.

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

Siehe auch

Referenz

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 und .NET Framework 3.5

Exemplarische Vorgehensweise: Erstellen eines Smarttags mit einer Anpassung auf Dokumentebene