Rafael1119

Here is the short version:

Is it possible to reference a form region and its controls via the Item_Send() event handler Some samples will be nice.

Detailed version:

I have a VSTO AddIn with a Form Region for IPM.Appointment messageclass and I'm trying to use it so that I can send a meeting request to my recipients and include private information on the form region visible to only those users with the form region AddIn installed.

The problem I've ran into is that when I compose the message on IPM.Appointment, the data I entered in the form region is lost when I send the meeting request given that the the form being used is different(IPM.Schedule.Meeting.Request).

My thought is to copy the data from the appointment form to the meeting request form on its way out using the Item_Send() event but I have not been able to find good examples/code to reference a form region and its controls.

Thanks all!

Rafael



Re: Visual Studio Tools for Office reference Form Region controls from Item_Send()

X4U

Hello Rafael,

haven't a sample for a FormRegion, but for Frompages.

The technique should be just the same - instead that you can use .Net controls and not Forms 20 controls.

Have a look here if that can help you:

http://forums.microsoft.com/MSDN/showpost.aspx postid=1985969&siteid=1

You can get the Active Inspector by using Globals.ThisAddin.Application.ActiveInspector()

Hope this helps,

greets, Helmut






Re: Visual Studio Tools for Office reference Form Region controls from Item_Send()

Rafael1119

I follow the pages example a bit but not sure how to translate that into handling form region events. I am just learning this stuff on Form Regions and AddIn so not sure what you mean by .Net controls or how to reference them.

Not sure if I follow this whole thing but how are Form Regions supposed to replace Custom Forms when they don't seem to be a good candidate to transport data within the organization the same way Custom Forms do today.

I have an appointment custom form with one page where I distribute private information to internal employees that I would like to upgrade to Forms Region since my company plans to upgrade to Exchagne 2007 but either I'm going about this the wrong way or Form Regions are not intended to be used this way

Thanks for the reply however, I've used your x4u stuff before and it's been quite handy as I start to play with Outlook AddIns.

Rafael





Re: Visual Studio Tools for Office reference Form Region controls from Item_Send()

Ji Zhou – MSFT

Rafael1119 wrote:

The problem I've ran into is that when I compose the message on IPM.Appointment, the data I entered in the form region is lost when I send the meeting request given that the the form being used is different(IPM.Schedule.Meeting.Request).

My thought is to copy the data from the appointment form to the meeting request form on its way out using the Item_Send() event but I have not been able to find good examples/code to reference a form region and its controls.

Hi Rafael,

Of course, we can get reference of custom form and its controls in ItemSend event handle. I just follow and modify a walkthrough from MSDN (tell us how to create a Form Region in Our Add-in): http://msdn2.microsoft.com/en-us/library/aa942741(VS.80).aspx

In fact, I create a Class FormRegionTest which is derived from Outlook.FormRegionStartup. And then I declared three public variables in that Class, as types: Outlook.FormRegion, UserForm, Outlook.OlkTextBox. Then in BeforeFormRegionShow Method, we set these variables to the real custom form and the form’s controls. Codes are like these:

Code Snippet

public Outlook.FormRegion FormRegion;

public UserForm UserForm;

public Outlook.OlkTextBox OlkTextBox1;

public void BeforeFormRegionShow(Microsoft.Office.Interop.Outlook.FormRegion FormRegion)

{

this.FormRegion = FormRegion;

this.UserForm = FormRegion.Form as UserForm;

try

{

OlkTextBox1 = UserForm.Controls.Item("TextBox1") as Outlook.OlkTextBox;

}

catch (Exception ex)

{

MessageBox.Show(ex.ToString());

}

}

After that done, in Add-in Class, you should declare a instance of FormRegionTest and assign its value the same as what you return from RequestService Method. Codes are like these:

Code Snippet

private FormRegionTest formRegionTest = null;

protected override object RequestService(Guid serviceGuid)

{

if (serviceGuid == typeof(Microsoft.Office.Interop.Outlook.FormRegionStartup).GUID)

{

formRegionTest = new FormRegionTest();

return formRegionTest;

}

else

{

return base.RequestService(serviceGuid);

}

}

Then in Item_Sent event handle, we can use formRegion.UserForm to access the custom form and formRegionTest.OlkTextBox to access the TextBox1 control on the form. Codes:

Code Snippet

void Application_ItemSend(object Item, ref bool Cancel)

{

MessageBox.Show(formRegionTest.OlkTextBox1.Text);

}

Wish this can help!

But I am still not very sure about if your objective can be achieved by the means you mentioned above, because we cannot tell when ItemSend method gets performed, if we can still access the Meeting Request Form and write data to it. You can have a try. Good luck!

Exactly speaking, this is a little off topic here, Outlook Newsgroup will be a better place J

Thanks

Ji






Re: Visual Studio Tools for Office reference Form Region controls from Item_Send()

Rafael1119

Hi Ji and thanks for your reply. This looks good but before I can test this out, I ran into some hopefully minor issues when implementing this code.

The Form Region AddIn walk-through I used already has a function like the one you suggested so I am not sure how to combine these two:

' This code is from a walk-through I found on technet

Protected Overrides Function RequestService(ByVal serviceGuid As Guid) As Object
If serviceGuid = GetType(Microsoft.Office.Interop.Outlook.FormRegionStartup).GUID Then
Return New FormRegionHookup()
Else
Return MyBase.RequestService(serviceGuid)
End If

End Function 'RequestService

The "RequestService" above is highlighted and says: multiple defininitions with identical signatures

' This is your code (Ji)

Private formRegionTest As formregionTest = Nothing

Protected Overloads Overrides Function RequestService(ByVal serviceGuid As Guid) As Object
If serviceGuid = GetType(Microsoft.Office.Interop.Outlook.FormRegionStartup).GUID Then
formRegionTest = New formregionTest()
Return formRegionTest
Else
Return MyBase.RequestService(serviceGuid)
End If
End Function

Also, is the messagebox you have on the item send returning the value of the meeting invite or the current value of the appointment item

Thanks,

Rafael





Re: Visual Studio Tools for Office reference Form Region controls from Item_Send()

Ji Zhou – MSFT

Hi Rafael,

The difference between my codes and codes in walk-through results from I did not use the walk-through’s Class name. In fact, FormRegionHookup in walk-through and FormRegionTest in my codes are the same class. When I write a test, I just rename it in my custom way.

So if you use the default name in the walk-through. You can write like these:

Private frh As FormRegionHookup = Nothing

Protected Overloads Overrides Function RequestService(ByVal serviceGuid As Guid) As Object
If serviceGuid = GetType(Microsoft.Office.Interop.Outlook.FormRegionStartup).GUID Then
frh = New FormRegionHookup ()
Return frh
Else
Return MyBase.RequestService(serviceGuid)
End If
End Function

With the codes above, you should use MessageBox.Show(frh.OlkTextBox1.Text) below. We do this just for keeping a reference of FormRegionHookup in Class-level. So we will be able to access our custom form and controls through the variable frh later in ItemSend method.

The messagebox returns a string of the textbox in our custom form.

Thanks

Ji






Re: Visual Studio Tools for Office reference Form Region controls from Item_Send()

Rafael1119

I think I follow that Ji but I must have made some weird change to the walk-through class because I do not get the reference to the olkTextBox1 textbox from the FormRegionHookup class but I do see in your example. Here is the class as I have it now:

Imports System.Runtime.InteropServices
Imports Outlook = Microsoft.Office.Interop.Outlook
Imports Microsoft.Vbe.Interop.Forms
Imports System.Windows.Forms


<ComVisible(True), _
Guid("88F7BFBE-7666-4a0c-BCFD-2740E6625E04"), _
ProgId("LMFormRegionAddIn.FormRegionHookup"), _
ClassInterface(ClassInterfaceType.AutoDual)> _
Public Class FormRegionHookup
Implements Outlook.FormRegionStartup
Private FormRegion As Outlook.FormRegion
Private userForm As UserForm
Private WithEvents OlkTextBox1 As Outlook.OlkTextBox
Private OlkTextBox2 As Outlook.OlkTextBox

' Returns FormRegion.ofs from the resource collection of the current Addin project.
Public 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
Application.DoEvents()
Select Case FormRegionName
Case "MyFormRegion"
Dim ofsBytes As Byte()
ofsBytes = My.Resources.MyFormRegion
Return ofsBytes

Case Else
Return Nothing
End Select
End Function

' Maps the fields you defined in the FormRegionHookup class to controls on the form region
Public Sub BeforeFormRegionShow(ByVal FormRegion As Outlook.FormRegion) _
Implements Outlook.FormRegionStartup.BeforeFormRegionShow
Me.FormRegion = FormRegion
Me.userForm = FormRegion.Form

Try
OlkTextBox1 = TryCast(userForm.Controls.Item("OlkTextBox1"), Outlook.OlkTextBox)
Catch ex As Exception
MessageBox.Show(ex.ToString())
End Try
End Sub

Public Function GetFormRegionManifest( _
ByVal formRegionName As String, _
ByVal LCID As Integer) As Object _
Implements Outlook.FormRegionStartup.GetFormRegionManifest
Throw New Exception("The method or operation is not implemented.")
End Function
Public Function GetFormRegionIcon( _
ByVal formRegionName As String, _
ByVal LCID As Integer, _
ByVal icon As Outlook.OlFormRegionIcon) As Object _
Implements Outlook.FormRegionStartup.GetFormRegionIcon
Throw New Exception("The method or operation is not implemented.")
End Function

End Class

Not sure what's going on. However when I tried to copy these functions to your class the same thing happened where I did not see the olkTextBox1 as an option after I typed formRegionTest.

Thanks,

Rafael





Re: Visual Studio Tools for Office reference Form Region controls from Item_Send()

Ji Zhou – MSFT

Hi Rafael,

As I mentioned in my first post, we should declare our control and form as public variable. So we can access them from out of the Class:

Public FormRegion As Outlook.FormRegion
Public userForm As UserForm
Public WithEvents OlkTextBox1 As Outlook.OlkTextBox
Public OlkTextBox2 As Outlook.OlkTextBox

Thanks

Ji






Re: Visual Studio Tools for Office reference Form Region controls from Item_Send()

Rafael1119

I am such a newbie... thanks for taking the time to state the obvious. I can now display the data of the outgoing Item it appears but not really.

As you expected though ( I think) this code does not do what I wanted to do. Data displayed on the OlkTextBox1 is the data from the item opened on the inspector so any changes to the OlkTextBox1 from the Item_Send event, will only update the calendar appointment that I am working with.

I noticed the data stays on the Form Region while the item is in the Outbox folder but once it goes out and is moved to the Sent Items, the form region control lose their values and they show up empty.

Use the inspector and listen for item being created perhaps Really stuck with this issue.

Thanks,

Rafael