日期:2013-03-16  浏览次数:20493 次

How to handle events in Word by using Visual C# .NET
适用于
IN THIS TASK
SUMMARY
Recognize events that are supported by Word 2000, by Word 2002, and by Word 2003
Recognize events that are supported by Word 2002 and by Word 2003
Recognize events that are supported by Word 2003
Create a Visual C# .NET Automation client that handles Word events
Test the code
REFERENCES
SUMMARY
This article describes how to handle events in Microsoft Word 2000, in Word 2002, and in Microsoft Office Word 2003 from an Automation client that is created by using Microsoft Visual C# .NET.

back to the top
MORE INFORMATION
With Visual C# .NET, Word events are based on delegates. Word defines the events that it will raise, providing callback functions. The delegate is a template for a single method that meets the requirements of Word for the callback function for one event. The Visual C# .NET program creates a specific object that is based on that delegate. That object complies with the requirement for the Word callback function for a specific reference.
Recognize events that are supported by Word 2000, by Word 2002, and by Word 2003
+-------------------------------------------------------------------------------+
| Event | Description |
+-------------------------------------------------------------------------------+
| Close | Occurs when a document is closed. |
+-------------------------------------------------------------------------------+
| DocumentBeforeClose | Occurs immediately before any open document closes. |
+-------------------------------------------------------------------------------+
| DocumentBeforePrint | Occurs before any open document is printed. |
+-------------------------------------------------------------------------------+
| DocumentBeforeSave | Occurs before any open document is saved. |
+-------------------------------------------------------------------------------+
| DocumentChange | Occurs when a new document is created, when an |
| | existing document is opened, or when another |
| | document is made the active document. |
+-------------------------------------------------------------------------------+
| DocumentOpen | Occurs when a document is opened. |
+-------------------------------------------------------------------------------+
| GotFocus | Occurs when the focus is moved to an embedded |
| | ActiveX control. |
+-------------------------------------------------------------------------------+
| LostFocus | Occurs when the focus is moved from an embedded |
| | ActiveX control. |
+-------------------------------------------------------------------------------+
| New | Occurs when a new document that is based on the |
| | template is created. A procedure for the New event |
| | runs only if it is stored in a template. |
+-------------------------------------------------------------------------------+
| NewDocument | Occurs when a new document is created. |
+-------------------------------------------------------------------------------+
| Open | Occurs when a document is opened. |
+-------------------------------------------------------------------------------+
| Quit | Occurs when the user qui