Programming Against Events

When you create Word solutions, you usually write code that responds to actions that users take within your application. For example, you might add a button to the toolbar that performs an action when the user clicks the button. When you create VBA solutions for Word, it is difficult to write code that responds to user actions—such as selecting text—because most of the objects available in the Word object model do not have events that you can capture.

The enhancements that VSTO adds to host items and host controls expose events on these objects, and you can program against a number of them. Several events are exposed on the Document, and on the Bookmark, XMLNode, and XMLNodes controls. When you create VBA solutions for Word, you cannot write code in response to a user moving the cursor into an area of text that contains a bookmark. With VSTO, this is now possible.

In this section you will look at the events for each of the host controls and the Document host item.

0 0

Post a comment