Word Host Items and Host Controls

VSTO enhances a number of Word objects by enabling data binding and by exposing events. The VSTO enhancements are in the form of controls that can be added to a container. The container is known as the host item, and the controls that the host item contains are called host controls.

Host controls are added to host items in much the same way you add a control to a UserForm. For example, in VSTO, the Bookmark host control has events and can be bound to data, and the Document is a host item on which you can add the Bookmark host control (as well as other host controls and Windows Forms controls). Figure 6.2 shows a Bookmark control named Bookmark1, with all its properties listed in the Properties window.

Figure 6.2. Events of a Bookmark host control

Host items and host controls wrap the native Office objects; they have the same functionality as the underlying object, but they are enhanced with data binding capabilities and events. The native objects are in the Microsoft.Office.Interop.Word namespace. In this book, we sometimes refer to these objects as Interop objects. The host items and host controls are in the Microsoft.Office.Tools.Word namespace, and we sometimes refer to these objects as VSTO objects or VSTO controls. Three host controls can be added to the host item document: Bookmark, XMLNode, and XMLNodes.

You can add host controls only to a host item. When you create a VSTO solution and choose either a document or a template, it is automatically created as a host item, enabling you to add host controls to the document at design time and at run time. However, if you programmatically add a new document, it will be of the type Microsoft.Office.Interop.Word.Document and cannot have VSTO or Windows Forms controls added to it.

0 0

Post a comment