Question

The outlook PropertyPage Interface requires a Read Only Boolean Property Dirty.

When this is set to true, the Apply button from the property page options dialog will become enabled.

Apply

According to this walkthrough, you have to call OnStatusChange to notify the UI that the value of Dirty has changed.

Purportedly, this is available by calling the following:

Dim ppSite As Outlook.PropertyPageSite = Parent
ppSite.OnStatusChange()

But Parent always returns nothing so I have no mechanism to tell the UI when I have updated the dirty flag.

How can I do this?


I'm using the basic steps produced in this discussion to setup the options page.
Here's a full implementation of my code:

Added New User Control called SendReminderOptions:

<ComVisible(True)>
Public Class SendReminderOptions : Inherits UserControl : Implements Outlook.PropertyPage

    Const captionDispID As Integer = -518

    Private _dirty As Boolean = False
    Public ReadOnly Property Dirty As Boolean Implements Microsoft.Office.Interop.Outlook.PropertyPage.Dirty
        Get
            Return _dirty
        End Get
    End Property

    Public Sub SetDirty(newValue As Boolean)
        _dirty = newValue
        Dim ppSite As Outlook.PropertyPageSite = Parent
        ppSite.OnStatusChange()
    End Sub

    <DispId(captionDispID)> _
    Public ReadOnly Property PageCaption() As String
        Get
            Return "Send Reminder Options"
        End Get
    End Property

    Public Sub GetPageInfo(ByRef HelpFile As String, ByRef HelpContext As Integer) Implements Microsoft.Office.Interop.Outlook.PropertyPage.GetPageInfo

    End Sub

    Public Sub Apply() Implements Microsoft.Office.Interop.Outlook.PropertyPage.Apply

    End Sub

End Class

Added the following code to ThisAddIn

Private Sub ThisAddIn_Startup() Handles Me.Startup
    Dim myOutlook As Outlook.Application = Globals.ThisAddIn.Application
    AddHandler myOutlook.OptionsPagesAdd, AddressOf AddOptionsPage
End Sub

Private Sub AddOptionsPage(ByVal pages As PropertyPages)
    pages.Add(New SendReminderOptions(), "Options")
End Sub
Was it helpful?

Solution

This function gets the parent PropertyPageSite Object using Reflection. It must be called in Load event.

Visual Basic

Private Function GetPropertyPageSite() As Outlook.PropertyPageSite
    Dim objType As Type = GetType(System.Object)
    Dim assemblyPath As String = objType.Assembly.CodeBase.Replace("mscorlib.dll", "System.Windows.Forms.dll").Replace("file:///", "")
    Dim assemblyName As String = System.Reflection.AssemblyName.GetAssemblyName(assemblyPath).FullName

    Dim unsafeNativeMethods As Type = Type.[GetType](System.Reflection.Assembly.CreateQualifiedName(assemblyName, "System.Windows.Forms.UnsafeNativeMethods"))
    Dim oleObjectType As Type = unsafeNativeMethods.GetNestedType("IOleObject")

    Dim methodInfo As System.Reflection.MethodInfo = oleObjectType.GetMethod("GetClientSite")
    Dim propertyPageSite As Object = methodInfo.Invoke(Me, Nothing)

    Return DirectCast(propertyPageSite, Outlook.PropertyPageSite)
End Function

CSharp

private Outlook.PropertyPageSite GetPropertyPageSite()
{
    Type objType  = typeof(System.Object);
    string assemblyPath = objType.Assembly.CodeBase.Replace("mscorlib.dll", "System.Windows.Forms.dll").Replace("file:///", "");
    string assemblyName = System.Reflection.AssemblyName.GetAssemblyName(assemblyPath).FullName;

    Type unsafeNativeMethods = Type.GetType(System.Reflection.Assembly.CreateQualifiedName(assemblyName, "System.Windows.Forms.UnsafeNativeMethods"));
    Type oleObjectType = unsafeNativeMethods.GetNestedType("IOleObject");

    System.Reflection.MethodInfo methodInfo = oleObjectType.GetMethod("GetClientSite");
    Object propertyPageSite = methodInfo.Invoke(this, null);

    return (Outlook.PropertyPageSite)propertyPageSite;
}

From How to implement OL PropertyPage / Customize Outlook Options Dialog

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top