共用方式為


Document.ActivateEvent Event

Definition

Occurs when the document becomes the active window.

public:
 event Microsoft::Office::Tools::Word::WindowEventHandler ^ ActivateEvent;
event Microsoft.Office.Tools.Word.WindowEventHandler ActivateEvent;
member this.ActivateEvent : Microsoft.Office.Tools.Word.WindowEventHandler 
Event ActivateEvent As WindowEventHandler 

Event Type

Examples

The following code snippet displays a message when the document is activated. This example is for an application-level add-in.

private void DocumentActivateEvent()
{
    Document vstoDoc = Globals.Factory.GetVstoObject(this.Application.ActiveDocument);
    vstoDoc.ActivateEvent += new Microsoft.Office.Tools.Word.WindowEventHandler(ThisDocument_ActivateEvent);
}

void ThisDocument_ActivateEvent(object sender, Microsoft.Office.Tools.Word.WindowEventArgs e)
{
    System.Windows.Forms.MessageBox.Show("The document has been activated");
}
Private Sub DocumentActivateEvent()
    Dim vstoDoc As Document = Globals.Factory.GetVstoObject(Me.Application.ActiveDocument)
    AddHandler vstoDoc.ActivateEvent, AddressOf ThisDocument_ActivateEvent
End Sub

Private Sub ThisDocument_ActivateEvent(ByVal sender As Object, _
    ByVal e As Microsoft.Office.Tools.Word.WindowEventArgs)
    System.Windows.Forms.MessageBox.Show("The document has been activated")
End Sub

Remarks

The ActivateEvent event occurs only when you move the focus within an application. Moving the focus to or from an object in another application does not trigger the event.

Applies to