outlook PropertyPage
界面需要只读布尔属性Dirty
。
当此项设置为true
时,属性页选项对话框中的“应用”按钮将变为启用状态。
根据此walkthrough,您必须致电OnStatusChange
以通知用户界面Dirty
的值已更改。
据称,可以通过以下方式获取:
Dim ppSite As Outlook.PropertyPageSite = Parent
ppSite.OnStatusChange()
但Parent
总是不返回任何内容,所以当我更新脏标志时,我没有机制告诉用户界面。
我该怎么做?
我正在使用此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
答案 0 :(得分:2)
此函数使用Reflection获取父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