Outlook Property Pages in .Net

T

Tobias

Has anyone been able to code an Outlook property page,
with a VS.Net User control wrapped in a C++ activeX Shim
project?

Currently trying to get the VSIDE.EXE sample from MSDN
working with a VB.Net User Control that i have coded as a
class that implements IPropertyPageSite.

I have got it to work without a seperate shim, (my VB.Net
Shared Addin already has a Shim), the controls and code
processes on the page work, however when you click apply
or Ok to commit your changes and/or close the window, an
error occurs.
So Im guessing Ill need a seperate shim for the .net
property page, as per Andys comments in the code for his
article "Building Outlook 2002 Addins with VB.Net".
--> Refer to the comments in the OptionsPageAdd event for
more information.
The other way to do this which is dead easy is to deploy
the propertypages control in a VB6 DLL as an ActiveX
control; while this is fairly easy, im really not
interested in going back to VB6.0 if at all possible.
 
T

Torsten Darmer

Hy,

Create an usercontrol in Vb.NET
for example

Public Class PropPage

Inherits System.Windows.Forms.UserControl

Implements Microsoft.Office.Interop.Outlook.PropertyPage

Friend oSite As Outlook.PropertyPageSite

Private boolInitializing As Boolean

Private m_fDirty As Boolean

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

' Code to set properties according to the user's

' selections goes here.

Try

m_fDirty = False

Catch ex As System.Exception

End Try

End Sub

Public ReadOnly Property Dirty() As Boolean Implements
Microsoft.Office.Interop.Outlook.PropertyPage.Dirty

Get

Dirty = m_fDirty

End Get

End Property

Private Sub SetDirty()

If Not oSite Is Nothing Then

m_fDirty = True

oSite.OnStatusChange()

End If

End Sub

Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)

Try

oSite = CType(Parent, Outlook.PropertyPageSite) 'its always nothing,
because Parent is COM

If oSite Is Nothing Then

Dim erg As Boolean = SetParent 'Thats the way

If oSite Is Nothing Then

MessageBox.Show("Error")

End If

End If

Catch ex As Exception

End Try

End Sub

Public ReadOnly Property SetParent() As Boolean

Get

Dim strAssembly As String

strAssembly = Type.GetType("System.Object").Assembly.CodeBase

strAssembly = strAssembly.Replace("mscorlib.dll", _

"System.Windows.Forms.dll")

strAssembly = strAssembly.Replace("file:///", String.Empty)

strAssembly = Reflection.AssemblyName.GetAssemblyName(strAssembly).FullName

Dim qualifiedControlTypeName As String = _

Reflection.Assembly.CreateQualifiedName(strAssembly,
"System.Windows.Forms.Control")

Dim ct As Type = Type.GetType(qualifiedControlTypeName)

Dim bf As Reflection.BindingFlags = _

Reflection.BindingFlags.IgnoreCase Or _

Reflection.BindingFlags.NonPublic Or _

Reflection.BindingFlags.Public Or _

Reflection.BindingFlags.Static Or _

Reflection.BindingFlags.Instance

Dim pi() As Reflection.PropertyInfo = ct.GetProperties(bf)

Dim axipi As Reflection.PropertyInfo = getMemberByName(pi, _

"ActiveXInstance")

Dim axi As Object = axipi.GetValue(Me, Nothing)

Dim site As Object = axi.GetClientSite()

If site Is Nothing Then

Return True

Else

oSite = CType(site, Outlook.PropertyPageSite)

End If

Dim qualifiedActiveXImplTypeName As String = _

Reflection.Assembly.CreateQualifiedName(strAssembly,
"System.Windows.Forms.Control+ActiveXImpl")

Dim axit As Type = Type.GetType(qualifiedActiveXImplTypeName)

pi = axit.GetProperties(bf)

Dim dmpi As Reflection.PropertyInfo = getMemberByName(pi, "DesignMode")

Dim ret As Boolean = dmpi.GetValue(axi, Nothing)

If ret Then

Return True

End If

Return False



End Get

End Property

<DispId(-518)> _

Public ReadOnly Property Caption() As String 'the displayname on the Tab

Get

Return Me.Name

End Get

End Property

Private Function getMemberByName(ByVal pi() As Reflection.PropertyInfo,
ByVal Suche As String) As Reflection.PropertyInfo

Dim xpi As Reflection.PropertyInfo

For Each xpi In pi

If xpi.Name = Suche Then

Return xpi

End If

Next

End Function



This example is converted from an c# news example

Torsten
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top