none
e.cancel = true is not working in FormRegionInitializing event RRS feed

  • Question

  • Hi, I am developing an addin for Outlook 2013. The addin contains contains a form region. In some situations I want to cancel the showing of the form region and therefore I tried to set e.cancel = true in FormRegionInitializing event method. The form region is still being shown. The documentation says:

    To prevent the form region from appearing, set e.cancel = true.

    Thats what I do, but unfortunately it doesn't work that way.

    Best regards

    Esben Rud Nielsen, Bankdata

     
    Friday, January 10, 2014 7:02 AM

Answers

  • If your form region is a ReplaceAll type and you cancel display of the form region what would you expect to be displayed? The only possible form to display would be the original form for that class of item.

    If the form region is displayed it replaces the entire default form, if not the default form would be displayed.

    When you cancel display, what is the MessageClass of the item that's displayed? If you don't cancel what is the MessageClass?


    Ken Slovak MVP - Outlook

    Friday, January 10, 2014 4:49 PM
    Moderator

All replies

  • Hello Esben,

    Did you try to debug? Is the FormRegionInitializing event handler called? What Outlook version do you use?

    Please take a look at the How to: Prevent Outlook from Displaying a Form Region article in MSDN. It provides the following sample code:

    private void MapItFactory_FormRegionInitializing(object sender,
        Microsoft.Office.Tools.Outlook.FormRegionInitializingEventArgs e)
    {
        Outlook.ContactItem myItem = (Outlook.ContactItem)e.OutlookItem;
    
        if (myItem != null)
        {
            if ((myItem.BusinessAddress != null &&
                    myItem.BusinessAddress.Trim().Length > 0) ||
                (myItem.HomeAddress != null && 
                    myItem.HomeAddress.Trim().Length > 0) ||
                (myItem.OtherAddress != null && 
                    myItem.OtherAddress.Trim().Length > 0))
            {
                return;
            }
        }
    
        e.Cancel = true;
    }
    

    Friday, January 10, 2014 9:48 AM
  • Hi, YES I always debug. The cancel flag is false on entry to FormRegionInitializing method, I turn cancel on. My fomregion is of type ReplaceAll. Allthough I set e.cancel = true, the form is still displayed, but it's the default form for IPM.Note that gets displayed. When I leave e.cancel as false then my own form gets displayed. I can see that the caller of FormRegionInitializing is testing on e.cancel flag but I get the default IPM.Note form displayed instead but maybe that what e.cancel = true is for. Looking onto the code of the caller would demystify this issue.

    Maybe the documentation should say: To prevent the form region from appearing, set e.Cancel = true. The default form for the message class is displayed instead.

    Regards Esben

    Friday, January 10, 2014 10:03 AM
  • Hi Esben,

    I have just tried to reproduce the issue in my Outlook 2013. But I have successfully disabled the form region at runtime in Outlook using the following code:

    Private Sub FormRegion1Factory_FormRegionInitializing(ByVal sender As Object, ByVal e As Microsoft.Office.Tools.Outlook.FormRegionInitializingEventArgs) Handles Me.FormRegionInitializing
         e.Cancel = True
    End Sub

    What message class did you specify for your form? The fact is that even Visual Studio doesn't allow to choose the standard message class from the list of available ones:

    For replacement and replace-all form regions, you can specify a new custom message class name. You do not need to use the message class name of an existing custom form. The name of the custom message class must be unique. One way to ensure that the name is unique is to use a naming convention similar to the following: <StandardMessageClassName>.<Company>.<MessageClassName> (for example: IPM.Note.Contoso.MyMessageClass).

    Are you able to reproduce the issue with a newly created sample add-in project? If so, could you please upload to any web server or service? I will test it on my machine.

    P.S. Please make sure that you have all the latest updates installed for Outlook/Office. Do you have any other add-ins installed for Outlook?

     


    Friday, January 10, 2014 11:05 AM
  • Hi, I use this message class name: IPM.Note.SMS. I just created the project some days ago. You can get a zip of the project at: http://netbryggeriet.dk/OutlookAddIn1.zip

    I haven't applied any updates, just installed Office 2013 and selected Outlook, Word and some other products.

    Best regards Esben

    Friday, January 10, 2014 11:24 AM
  • If your form region is a ReplaceAll type and you cancel display of the form region what would you expect to be displayed? The only possible form to display would be the original form for that class of item.

    If the form region is displayed it replaces the entire default form, if not the default form would be displayed.

    When you cancel display, what is the MessageClass of the item that's displayed? If you don't cancel what is the MessageClass?


    Ken Slovak MVP - Outlook

    Friday, January 10, 2014 4:49 PM
    Moderator
  • In both situations the message class is IPM.Note.SMS.

    It looks like, I should look for a way to close the inspector instead.

    Esben

    Friday, January 10, 2014 5:37 PM