none
Outlook Form Region - Collapse by default on opening (C#) RRS feed

  • Question

  • Is there a way around, or is there any intention, to expose the 'Expanded' Event from within an Outlook Form Region?

    It seems odd that you can bind to the event to listen to it's result (whether it has just expanded or collapsed through the isExpanded property) but you can't bind to it to cancel or even call the method itself to programatically expand and collapse the form region from within code.

    Example:

        this.OutlookFormRegion.Expanded += Handle_Expanded(); // You can listen

       this.OutlookFormRegion.Expanded(false|true) // But you can't call it

    I need a way of having the form region minimised by default when an inspector window is opened. I don't care much for handling it programatically after as such; I just want it minimised by default. Is there maybe a registry key that can be set to handle this? 


    • Edited by djjohnjosephuk Thursday, December 15, 2016 12:50 PM Question title more appropriate
    Wednesday, December 14, 2016 11:26 AM

Answers

  • OK so I've been doing a bit of testing with this. Seems like changing that particular binary value is not having any effect, even though it's the only value that changes when the form region is collapsed/expanded.

    What I've tried:

    RegistryKey registryKey = Registry.CurrentUser.OpenSubKey(

        @"Software\Microsoft\Office\14.0\Outlook\FormRegions\ReadInspectors",

        true

    );
    byte[] data = (byte[])registryKey.GetValue("IPM.Appointment#Appointment");
    data[(data.Length - 4)] = 0x01;
    registryKey.SetValue("IPM.Appointment#Appointment", data, RegistryValueKind.Binary);

    First things first am I setting that value correctly? It does save back to the registry but I'm not sure if I'm updating the byte array correctly.

    EDIT: Ahah! Setting the registry key on 'SendInspectors' instead of 'ReadInspectors' did the trick! Setting that on the ThisAddIn_Startup method seems to ensure that the form region is collapsed by default whenever a 'new appointment' item is opened. This now works perfectly!

    Thanks to Eugene above for your help! 



    Thursday, December 15, 2016 11:57 AM

All replies

  • Hello,

    The FormRegion object exposes an Expanded() event that passes a Boolean that tells whether the region is being expanded or collapsed. There's also an IsExpanded property that can be read (read-only).

    Outlook always first loads a form region in an expanded state and sets IsExpanded to True. If the initial state of the form region is to be collapsed, then Outlook immediately closes the form region, fires the Expanded event with the Expand parameter being False, and sets IsExpanded to False.

    There is no property or method for expanding or collapsing the Outlook form region. Only the Visible property of the FormRegion class is available for developers.

    Note, Add-in Express provides advanced Outlook form regions with properties and methods that allow to do so.


    profile for Eugene Astafiev at Stack Overflow, Q&A for professional and enthusiast programmers

    Wednesday, December 14, 2016 12:22 PM
  • Hi,

    Outlook remembers the state of a form region upon opening and reopening the appointment item, for example if I open it and minimise the form region, then close the item, and then reopen it again, the form region will be minimised. That must mean that Outlook stores somewhere a property or perhaps registry key that saves the state of the form region against the item. That property must be accessible in some way, as it must store it somewhere out of the codebase?

    Wednesday, December 14, 2016 1:23 PM
  • Thanks. I managed to find a later version of that page:

    https://msdn.microsoft.com/en-us/library/office/ff860990.aspx

    but the schema file within it seems to be down/moved:

    http://schemas.microsoft.com/office/outlook/12/formregion.xsd

    I was hoping the schema file might contain details of a property I could set or something along those lines ...


    Wednesday, December 14, 2016 2:22 PM
  • Try to use ProcessExplorer utility for searching the windows registry keys. See Lesson 5: Using Process Monitor to Troubleshoot and Find Registry Hacks for more information.

    profile for Eugene Astafiev at Stack Overflow, Q&A for professional and enthusiast programmers

    Wednesday, December 14, 2016 2:34 PM
  • Ah brilliant thanks for the information. After using process monitor to try and keep track of what registry keys are set when the appointment item is opened and closed with the form region expanded or collapsed, I managed to find a key that has different values depending on the form region state. I'm a bit stuck at the point however as I'm not sure how or if I can manipulate that registry value, which is a REG_BINARY.

    The key in question is:

    HKCU\Software\Microsoft\Office\14.0\Outlook\FormRegions\ReadInspectors\IPM.Appointment#Appointment

    This first screenshot is when the form region is expanded within the appointment, and the item has been closed:

    EDIT: Seems I cannot use images yet as my account is not verified.

    This next one is when the form region is collapsed and the appointment item closed:

    as you can see, the value on the bottom line, third in from the right has a value of 00 when expanded and 01 when collapsed. 

    Is there a way of setting this programmatically from my outlook add in (C#)? I guess the workflow in my head is that I need to grab this registry key from within my Microsoft.Office.Interop.Outlook.ItemEvents_10_OpenEventHandler(method)

    event, and set it to the collapsed value and save it back to the registry. I have no idea if this is feasible or not though, I'm fairly new to C# and completely new to registry key manipulation!



    Thursday, December 15, 2016 10:17 AM
  • OK so I've been doing a bit of testing with this. Seems like changing that particular binary value is not having any effect, even though it's the only value that changes when the form region is collapsed/expanded.

    What I've tried:

    RegistryKey registryKey = Registry.CurrentUser.OpenSubKey(

        @"Software\Microsoft\Office\14.0\Outlook\FormRegions\ReadInspectors",

        true

    );
    byte[] data = (byte[])registryKey.GetValue("IPM.Appointment#Appointment");
    data[(data.Length - 4)] = 0x01;
    registryKey.SetValue("IPM.Appointment#Appointment", data, RegistryValueKind.Binary);

    First things first am I setting that value correctly? It does save back to the registry but I'm not sure if I'm updating the byte array correctly.

    EDIT: Ahah! Setting the registry key on 'SendInspectors' instead of 'ReadInspectors' did the trick! Setting that on the ThisAddIn_Startup method seems to ensure that the form region is collapsed by default whenever a 'new appointment' item is opened. This now works perfectly!

    Thanks to Eugene above for your help! 



    Thursday, December 15, 2016 11:57 AM