hello
I still have problem,when I open multiple instances of Mail Compose
say 1,2, 3 & then send mail 2 then I get the values of form region
ctrl of mail 3 .I can get proper values in FormRegion_Close event but
that is fired after Application_ItemSend.
What's wrong with below code ?Do I've to use userproperties?
Thanks!
Class MailPreviewFormRegionWrapper
Inherits BaseFormRegionWrapper
Private m_Application As Outlook.Application
Private WithEvents m_Items As Outlook.Items
Shadows WithEvents FormRegion As Outlook.FormRegion
Shadows WithEvents UserForm As Forms.UserForm
Public Sub New(ByVal region As Outlook.FormRegion, ByVal application
As Outlook.Application)
m_Application = application
Me.Item = region.Item
Me.FormRegion = region
Me.UserForm = CType(FormRegion.Form, Forms.UserForm)
' Initalize region controls
InitializeControls()
' Find the contact and load those values
LoadValues()
End Sub
Public cmbMatter As Outlook.OlkComboBox
Private Sub InitializeControls()
' Turn off the scroll bars on this form
UserForm.ScrollBars =
Microsoft.Vbe.Interop.Forms.fmScrollBars.fmScrollBarsNone
Try
cmbMatter =
DirectCast(UserForm.Controls.Item("cmbMatter"),
Outlook.OlkComboBox)
cmbMatter.Text = ""
Catch ex As Exception
Debug.WriteLine("An error occured while hooking up
Form Region controls: " & ex.Message)
End Try
End Sub
Private Sub FormRegion_Close() Handles FormRegion.Close
If Not (m_Items Is Nothing) Then
m_Items = Nothing
End If
If Not cmbMatter Is Nothing Then cmbMatter = Nothing
RaiseClose()
End Sub
Private Sub LoadContactProperties()
'fill cmbMatter with values
End Sub
End Class
Public Class FormRegionHookupVB
Implements Outlook.FormRegionStartup
Private Const NOTE_REGION As String = "OutlookLawComposeMailPreview"
Private ComposecmbMatter As Outlook.OlkComboBox
Private Application As Outlook.Application
Private m_KnownRegions As List(Of
OutlookLawVB_VSTO.BaseFormRegionWrapper)
Public Sub New(ByVal outlookApplication As Outlook.Application)
Application = outlookApplication
m_KnownRegions = New List(Of
OutlookLawVB_VSTO.BaseFormRegionWrapper)
End Sub
Function GetFormRegionStorage(ByVal FormRegionName As String, ByVal
Item As Object, ByVal LCID As Integer, ByVal FormRegionMode As
Outlook.OlFormRegionMode, ByVal FormRegionSize As
Outlook.OlFormRegionSize) As Object Implements
Outlook.FormRegionStartup.GetFormRegionStorage
Try
Select Case FormRegionName
Case NOTE_REGION
Dim myItem As OutlookItem = New
OutlookItem(Item)
Dim mail As Outlook.MailItem =
CType(myItem.InnerObject, Outlook.MailItem)
Return My.Resources.ComposeMail
Case Else
Return Nothing
End Select
Catch ex As Exception
Debug.WriteLine(ex.Message)
Return Nothing
End Try
Sub BeforeFormRegionShow(ByVal FormRegion As Outlook.FormRegion)
Implements Outlook.FormRegionStartup.BeforeFormRegionShow
Try
Dim wrapper As
OutlookLawVB_VSTO.MailPreviewFormRegionWrapper = Nothing
Select Case FormRegion.InternalName
Case NOTE_REGION
wrapper = New
OutlookLawVB_VSTO.MailPreviewFormRegionWrapper(FormRegion,
Application)
ComposecmbMatter = wrapper.cmbMatter
End Select
If Not (wrapper Is Nothing) Then
m_KnownRegions.Add(wrapper)
End If
Catch ex As Exception
Debug.WriteLine(ex.Message)
End Try
End Sub
Public Function GetFormRegionManifest(ByVal FormRegionName As String,
ByVal LCID As Integer) As Object Implements
Microsoft.Office.Interop.Outlook._FormRegionStartup.GetFormRegionManifest
Select Case FormRegionName
Case NOTE_REGION
Return My.Resources.ComposeMailManifest
Case Else
Return Nothing
End Select
End Function
Public ReadOnly Property cmbMatter() As String
Get
cmbMatter = ComposecmbMatter.Text
End Get
End Property
End Class
public class ThisAddIn
Private ObjFormRegion As OutlookLawVB_VSTO.FormRegionHookupVB
Protected Overrides Function RequestService(ByVal serviceGuid As Guid)
_
As Object
If serviceGuid = _
GetType(Microsoft.Office.Interop.Outlook.FormRegionStartup).GUID Then
ObjFormRegion = New
OutlookLawVB_VSTO.FormRegionHookupVB(Me.Application)
Return ObjFormRegion
End If
Return MyBase.RequestService(serviceGuid)
End Function
Private Sub Application_ItemSend(ByVal Item As Object, ByRef Cancel As
Boolean) Handles Application.ItemSend
Dim strErrMsg As String, strXHeader As String
Try
AddTrace("Entering Application_ItemSend")
strXHeader = ObjFormRegion.cmbMatter
Catch ex As System.Exception
strErrMsg = "Error in Application_ItemSend" & "->" & ex.Message
AddTrace(strErrMsg)
errAddTrace(strErrMsg)
Finally
AddTrace("Exiting Application_ItemSend")
End Try
End Sub
End Class