当前位置:首页>>ASP.NET教程>>Asp.NET综合技巧>>如何用C#.NET处理WORD的事件
如何用C#.NET处理WORD的事件
2009/11/8 13:19:18
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 quits word. |
+-------------------------------------------------------------------------------+
| WindowActivate | Occurs when any document window is activated. |
+-------------------------------------------------------------------------------+
| WindowBeforeDoubleClick | Occurs when the editing area of a document window |
| | is double-clicked, before the default double-click |
| | action. |
+-------------------------------------------------------------------------------+
| WindowBeforeRightClick | Occurs when the editing area of a document window |
| | is right-clicked, before the default right-click |
| | action. |
+-------------------------------------------------------------------------------+
| WindowDeactivate | Occurs when any document window is deactivated. |
+-------------------------------------------------------------------------------+
| WindowSelectionChange | Occurs when the selection changes in the active |
| | document window. |
+-------------------------------------------------------------------------------+

back to the top
Recognize events that are supported by word 2002 and by word 2003
+-----------------------------------------------------------------------------+
| EPostageInsert | Occurs when a user inserts electronic postage |
| | in a document. |
+-----------------------------------------------------------------------------+
| EPostagePropertyDialog | Occurs when a user clicks the E-postage |
| | Properties button (located in the Labels and |
| | Envelopes dialog box) or the Print Electronic |
| | Postage toolbar button. This event permits a |
| | third-party software application to intercept |
| | and show their Properties dialog box. |
+-----------------------------------------------------------------------------+
| MailMergeAfterMerge | Occurs after all records in a mail merge have |
| | merged successfully. |
+-----------------------------------------------------------------------------+
| MailMergeAfterRecordMerge | Occurs after each record in the data source |
| | successfully merges in a mail merge. |
+-----------------------------------------------------------------------------+
| MailMergeBeforeMerge | Occurs when a merge is executed before any |
| | records merge. |
+-----------------------------------------------------------------------------+
| MailMergeBeforeRecordMerge | Occurs as a merge is executed for the |
| | individual records in a merge. |
+-----------------------------------------------------------------------------+
| MailMergeDataSourceLoad | Occurs when the data source is loaded for a |
| | mail merge. |
+-----------------------------------------------------------------------------+
| MailMergeDataSourceValidate | Occurs when a user performs address |