Share via


Classe Action (System 2007)

Aggiornamento: novembre 2007

Rappresenta un'azione smart tag di Visual Studio Tools per Office in un documento di Microsoft Office Word.

Spazio dei nomi:  Microsoft.Office.Tools.Word
Assembly:  Microsoft.Office.Tools.Word.v9.0 (in Microsoft.Office.Tools.Word.v9.0.dll)

Sintassi

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

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

Note

Le azioni sono le opzioni rese disponibili nel menu di scelta rapida Smart tag quando viene riconosciuto uno smart tag di un certo tipo. Un'azione possibile può essere, ad esempio, "Aggiungi nome alla cartella Contatti" per una stringa di tipo Nome utente. Per ulteriori informazioni sugli smart tag in Visual Studio Tools per Office, vedere Architettura degli smart tag.

Esempi

Nell'esempio di codice riportato di seguito viene illustrato come creare uno smart tag con un'azione. L'azione smart tag modifica la didascalia di menu dell'azione in fase di esecuzione e visualizza la posizione del testo riconosciuto. Per verificare l'esempio digitare le parole "termine" e "riconoscere" in diversi punti del documento, quindi provare l'azione smart tag.

Questo esempio è valido per una personalizzazione a livello di documento.

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

Gerarchia di ereditarietà

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

Codice thread safe

Qualsiasi membro static (Shared in Visual Basic) pubblico di questo tipo è thread-safe. I membri di istanza non sono garantiti come thread-safe.

Vedere anche

Riferimenti

Membri Action

Spazio dei nomi Microsoft.Office.Tools.Word

SmartTag

Altre risorse

Architettura degli smart tag

Procedura: aggiungere smart tag ai documenti di Word

Procedura: creare smart tag con sistemi di riconoscimento personalizzati in Word

Procedura dettagliata: creazione di uno smart tag tramite una personalizzazione a livello di documento