Getting a handle on a form region

M

Mark Lawrence

Outlook 2007, VS2008 with VSTO

I know about creating form regions, associating them with custom message
classes, adding controls to them, using the FormRegionShowing event to fill
the controls with data and so forth.

I'm having difficulty making some fundamental connection that I'd appreciate
pointers to information about.

I have buttons on the ribbon that are going to take action with the
information that's in the controls on the formregion. I need to get to the
controls to collect the data in them and save it off (in this particular
case, they're going to be sent to a database via a web service).

In the button click event handler, how do I get a hold of the object handle
for the form region? I thought about traversing the object hierarchy from
the ActiveInspector and that does lead to the ModifiedFormPages property
(holding a Pages) collection but when I check that property within the event
handler I find it's got a count of 0 even though I have a postItem with a my
form region showing. So I'm kind of scratching my head about how to traverse
down the object hierarchy to the form region.

Should I take an alternative path and call the Close method on the active
inspector and hang my data collection and saving work in the FormRegionClosed
event?
 
K

Ken Slovak - [MVP - Outlook]

When your init code is called to initialize the form region it probably is
passing an Outlook.FormRegion interface object. I do that in the
BeforeFormRegionShow() event handler. In that handler I call to Init() and
pass the FormRegion object passed to BeforeFormRegionShow() as "Region".

That FormRegion object is used to hook up the Close() and Expanded() event
handlers. The item showing the form region is Region.Item and the form
region form is Region.Form.

You can then cast the FormRegion.Form object to a Forms.UserForm object:

private Forms.UserForm _form; // at class level

// in init code

_form = (Forms.UserForm)Region.Form;

That lets you get the Controls collection of the form region, from there
it's easy to read/write the values in various controls in the form region.

For any controls that I might want to access later on I usually set up
variables to make it easy to access the control and its value later on. So I
might declare something like this for a form region date control:

private Outlook.OlkDateControl _timeToStartDate;

Then in my InitControls() code called from my Init() procedure I use
something like this:

_timeToStartDate =
(Outlook.OlkDateControl)_form.Controls.Item("olkTravelToStartDate");

Where "olkTravelToStartDate" is the name of a date control on the form
region.
 

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