place .NET custom control on custom form in Outlook 2003 and Outlook 2007

S

sd

hi!
1.is it possible to place .NET custom control on custom form(message/
contact) in outlook 2003 & 2007?(as it is not listed in additional
controls when designing form,THOUGH it is registered using regsvr32)
What extra steps r required in order to list it in additional
controls?
2.How to access Custom control built in vb placed on form region in
outlook 2007 from VSTO addIn?I was able to access OLk ctrls on Form
region in VSTO addin.I want to access custom controls custom
properties(getdata/setdata) in VSTO Addin?how to accomplish this using
vb.net
THanks!
 
K

Ken Slovak - [MVP - Outlook]

You can't add a .NET custom control to an Outlook form. All controls on
Outlook forms are either members of the Forms 2.0 library or are custom
ActiveX controls. You also shouldn't use the OLK* controls on a custom form
other than in a form region, they aren't tested for that and will cause
weird problems.

It doesn't matter whether or not you're using VSTO, you access any control
on a form the same way whether or not it's a custom control.
item.ModifiedFormPages("myPage").Controls.Item("myControl").
 
S

sd

Thanks!
I've one more question-I've designed form region for my custom form &
hook up my addin to this form region.(I referred
TravellAgencyAddInVB_VSTO)
now the form region adjoined to my custom form is shown when I
compose.But I want to access the ctrl values on this form region in
ItemSend event.How to get this?
In TravellAgencyAddInVB_VSTO addin they r accessed initially when
displaying the region(In MailPreviewFormRegionWrapper class)please
give some sample code snippet or any link that can be helpful.Thanks
again
 
K

Ken Slovak - [MVP - Outlook]

I don't have any code for that, but if you store a reference to your form
region for later you should be able to access it again in the send event
handler.
 
S

sd

hi!
I declared variables representing form region ctrls as public in
MailPreviewFormRegionWrapper class & obtained values of these ctrls in
HookUp class through readonly properties.Hence was able to access
values in application.ItemSend event.But if this will have any adverse
effect?
Thanks again !!
 
K

Ken Slovak - [MVP - Outlook]

As long as you release your objects per best practice I don't see why there
should be any bad effects. Are you seeing any?
 
S

sd

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
 
K

Ken Slovak - [MVP - Outlook]

I'm not going to analyze all that code, but I'd guess that you should use
bound fields from your form region to user properties so the values are
available at any time.
 

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