【问题标题】:Get Outlook.PropertyPageSite so you can call OnStatusChange() and update UI获取 Outlook.PropertyPageSite,以便您可以调用 OnStatusChange() 并更新 UI
【发布时间】:2014-02-03 03:05:16
【问题描述】:

outlook PropertyPage 接口需要只读布尔属性 Dirty

当设置为true 时,属性页选项对话框中的应用按钮将变为启用状态。

根据这个walkthrough,你必须调用OnStatusChange来通知UIDirty的值发生了变化。

据称,这可以通过调用以下方式获得:

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

但是Parent 总是什么都不返回,所以我没有机制告诉 UI 何时我更新了脏标志。

我该怎么做?


我正在使用此discussion 中生成的基本步骤来设置选项页面。
这是我的代码的完整实现:​​

添加了名为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

将以下代码添加到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

【问题讨论】:

    标签: .net vb.net outlook vsto outlook-addin


    【解决方案1】:

    此函数使用反射获取父对象PropertyPageSite。必须在 Load 事件中调用。

    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;
    }
    

    来自How to implement OL PropertyPage / Customize Outlook Options Dialog

    【讨论】:

    • 对如何获得 Window 句柄有任何想法吗?尝试为 WPF 窗口设置父级,但 PropertyPageSite 没有 Handle 属性。
    • @TheMuffinMan,哪个句柄?页面加载事件的处理程序?您可能想问另一个问题,其中包含完整的详细信息和指向此问题的链接。
    • 窗口句柄,IntPtr。不是事件处理程序。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-01
    • 2011-10-02
    • 2018-10-23
    • 2012-12-14
    相关资源
    最近更新 更多