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 given time.

Working with the Outlook Item Associated with the Inspector

An Inspector window is always associated with 1 of the 15 Outlook item types listed in Table 10-1. 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 15 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






Makes the Inspector window the active window with focus.



Read-only property that returns a string value containing the caption of the Inspector window.



Closes the Inspector window.



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



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



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



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


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 page of Outlook's Options dialog, users can set preferences for what kind of formats and editor they want to use when editing an Outlook item. The Options dialog can be accessed using the Options menu command in the Tools menu. Figure 11-6 shows this dialog. 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.

These settings help to 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 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 newly added button.

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

public partial class ThisApplication
 Office.CommandBarButton btn1;

 private void ThisApplication_Startup(object sender,
 EventArgs e)
 Outlook.MAPIFolder folder = this.Session.GetDefaultFolder(
 Outlook.Inspector inspector = this.Inspectors.Add(

 Office.CommandBar bar = inspector.CommandBars.Add(
 "My Command Bar", missing, missing, true);
 bar.Visible = true;

 btn1 = (Office.CommandBarButton)bar.Controls.Add(
 missing, missing, missing, true);
 btn1.Click += new 
 btn1.Caption = "My Custom Button";
 btn1.Tag = "OutlookAddin1.btn1";
 btn1.Style = Office.MsoButtonStyle.msoButtonCaption;

 void Btn1_Click(Office.CommandBarButton ctrl, 
 ref bool cancelDefault)
 MessageBox.Show("You clicked my button!");

 #region VSTO Designer generated code
 private void InternalStartup()
 this.Startup += new System.EventHandler(ThisApplication_Startup);

Part One. An Introduction to VSTO

An Introduction to Office Programming

Introduction to Office Solutions

Part Two. Office Programming in .NET

Programming Excel

Working with Excel Events

Working with Excel Objects

Programming Word

Working with Word Events

Working with Word Objects

Programming Outlook

Working with Outlook Events

Working with Outlook Objects

Introduction to InfoPath

Part Three. Office Programming in VSTO

The VSTO Programming Model

Using Windows Forms in VSTO

Working with Actions Pane

Working with Smart Tags in VSTO

VSTO Data Programming

Server Data Scenarios

.NET Code Security


Part Four. Advanced Office Programming

Working with XML in Excel

Working with XML in Word

Developing COM Add-Ins for Word and Excel

Creating Outlook Add-Ins with VSTO

Visual Studio Tools for Office(c) Using C# with Excel, Word, Outlook, and InfoPath
Visual Studio Tools for Office(c) Using C# with Excel, Word, Outlook, and InfoPath
ISBN: 321334884
Year: N/A
Pages: 214 © 2008-2020.
If you may any questions please contact us: