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