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

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

int

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

Left

int

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.

Top

int

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.

Width

int

Gets and sets the width of the Inspector window in pixels. This can only be set 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 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.OlDefaultFolders.olFolderInbox);
 Outlook.Inspector inspector = this.Inspectors.Add(
 folder.Items[1]);
 inspector.Display(missing);

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

 btn1 = (Office.CommandBarButton)bar.Controls.Add(
 Office.MsoControlType.msoControlButton, 
 missing, missing, missing, true);
 btn1.Click += new 
 Office._CommandBarButtonEvents_ClickEventHandler(
 Btn1_Click);
 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);
 }
 #endregion
}







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
EAN: N/A
Year: N/A
Pages: 214
Flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net