Working with the Inspector Object


The inspector window is the window in Outlook that shows detailed information for a particular Outlook item. This is the window that displays when you double-click an item in an Outlook folder. You can have multiple inspector windows open at any time.

Working with the Outlook Item Associated with the Inspector

An inspector window is always associated with 1 of the 16 Outlook item types listed in Table 10.1 in Chapter 10, "Working with Outlook Events." To get to the Outlook item associated with an Inspector object, use the CurrentItem property, which returns an Outlook item as an Object. You can cast the returned Object to 1 of the 16 Outlook item types.

Working with an Inspector Window

Table 11.5 lists several properties and methods that are used to set and get the position of an inspector window, as well as some other commonly used properties and methods related to the management of the window.

Table 11.5. Inspector Properties and Methods

Name

Type

Description

Activate()

 

Makes the inspector window the active window with focus.

Caption

String

Read-only property that returns a String value containing the caption of the inspector window.

Close()

 

Closes the inspector window.

Height

Integer

Gets and sets the height of the inspector window in pixels. This can be set only when the WindowState is set to OlWindowState.olNormalWindow.

Left

Integer

Gets and sets the left position of the inspector window in pixels. This can be set only when the WindowState is set to OlWindowState.olNormalWindow.

Top

Integer

Gets and sets the top position of the inspector window in pixels. This can be set only when the WindowState is set to OlWindowState.olNormalWindow.

Width

Integer

Gets and sets the width of the inspector window in pixels. This can be set only when the WindowState is set to OlWindowState.olNormalWindow.

WindowState

optional Object

Gets and sets the window state of the inspector window using the OlWindowState enumeration. Can be set to olMaximized, olMinimized, and olNormalWindow.


Working with Different Inspector Editor Types

In the Mail Format tab of Outlook's Options dialog box, users can set preferences for what kind of formats and editor they want to use when editing an Outlook item. The Options dialog box, shown in Figure 11.6, can be accessed using the Options menu command in the Tools menu. Two key options are what message format to use (HTML, Rich Text, or Plain Text) and whether to use Word as the editor of e-mail messages and rich text.

Figure 11.6. Picking formats and editor preferences in the Options dialog box.


These settings help determine what the Inspector object's EditorType property returns. EditorType returns a member of the OlEditorType enumeration: olEditorHTML, olEditorRTF, olEditorText, or olEditorWord. If the EditorType returns olEditorHTML, you can get to the HTML document object model for the inspector window by using the Inspector object's HTMLEditor property. Using the HTML document object model is an advanced topic and is not covered in this book.

If the user has chosen to use Word as his editor, the Inspector object's IsWordMail property returns TRue. This means that Outlook has started an instance of Word and is embedding the Word editor in the inspector window. Outlook has also created a Word Document to edit the Outlook item in. You can access Word's Document object by using the WordEditor property. This property returns an Object that you can cast to Word's Document object.

Adding Buttons and Menus to an Inspector Window

The Inspector object's CommandBars property returns a CommandBars object, which is defined in the Microsoft Office 11.0 Object Library PIA object. Outlook uses the same object model used by Word and Excel to work with buttons and menus associated with an inspector window. See Chapter 4, "Working with Excel Events," for more information on the CommandBars object hierarchy and examples of using the CommandBar objects. Listing 11.9 shows a simple VSTO add-in that creates a toolbar and a button in an inspector window and handles the click event for the new button.

Listing 11.9. A VSTO Add-In That Adds a Toolbar and a Button to an Inspector Window

Public Class ThisApplication   Private WithEvents btn1 As Office.CommandBarButton   Private Sub ThisApplication_Startup(ByVal sender As Object, _     ByVal e As System.EventArgs) Handles Me.Startup     Dim folder As Outlook.MAPIFolder     folder = Me.Session.GetDefaultFolder( _       Outlook.OlDefaultFolders.olFolderInbox)     Dim inspector As Outlook.Inspector = Me.Inspectors.Add( _       folder.Items(1))     inspector.Display()     Dim bar As Office.CommandBar = inspector.CommandBars.Add( _       "My Command Bar", Temporary:=True)     bar.Visible = True     btn1 = bar.Controls.Add( _       Office.MsoControlType.msoControlButton, _       Temporary:=True)     btn1.Caption = "My Custom Button"     btn1.Tag = "OutlookAddin1.btn1"     btn1.Style = Office.MsoButtonStyle.msoButtonCaption   End Sub   Private Sub Btn1_Click(ByVal ctrl As Office.CommandBarButton, _     ByRef cancelDefault As Boolean) Handles btn1.Click     MsgBox("You clicked my button!")   End Sub End Class 





Visual Studio Tools for Office(c) Using Visual Basic 2005 with Excel, Word, Outlook, and InfoPath
Visual Studio Tools for Office: Using Visual Basic 2005 with Excel, Word, Outlook, and InfoPath
ISBN: 0321411757
EAN: 2147483647
Year: N/A
Pages: 221

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net