none
How to control the display of FormRegion in Outlook? RRS feed

  • Question

  • Hello, I'm using VS2012 to develop an add-in for Outlook (2010). I created 2 FormRegion because the user can use two e-mail account and use each one FormRegion different. How do I display or hide FormRegion according to the account I'm using?
    Tuesday, September 10, 2013 6:00 PM

Answers

  • If each profile has one email account use what I said to use previously, NameSpace.CurrentUser.Address. If Exchange is involved you'll get an Exchange format address.

    Other than FormRegion.Visible about all you can do is to not supply the form region manifest or storage information when requested. That would cause an exception that you can probably handle to ignore.


    Ken Slovak MVP - Outlook

    • Marked as answer by Drausio Thursday, September 12, 2013 12:50 PM
    Wednesday, September 11, 2013 6:08 PM

All replies

  • Hi,

    Thank you for posting in the MSDN Forum.

    I'm trying to involve some senior engineers into this issue and it will take some time. Your patience will be greatly appreciated.

    Sorry for any inconvenience and have a nice day!

    Best regards,

    Fei


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Wednesday, September 11, 2013 2:15 PM
    Moderator
  • Is this one Outlook profile with 2 email accounts, or separate profiles?

    NameSpace.CurrentUser.Address will return the default email address for that Outlook profile.

    You can't really tell what address would be used for a specific email because the user could change the From address at any time until the email is sent. The account used for the email would be MailItem.SendUsingAccount and you can get the SmtpAddress property for that account, but if the default account is being used that property may be null.

    Based on the account you can have your business logic set the FormRegion.Visible Boolean property.


    Ken Slovak MVP - Outlook

    Wednesday, September 11, 2013 2:29 PM
  • Thank you Ken for your help, but I still have some doubts.

    Just clarifying, I have two profiles, each with an account.

    Question, where I can to set the Visible property? I tried in the ThisAddIn_Startup but gave error (Object reference not set to an instance of an object.) Then put in FormRegion2_FormRegionShowing.


            private void ThisAddIn_Startup(object sender, System.EventArgs e)
            {
                WindowFormRegionCollection formRegions = Globals.FormRegions[Globals.ThisAddIn.Application.ActiveExplorer()];
    
                formRegions.FormRegion2.Visible = false;
            }

            private void FormRegion2_FormRegionShowing(object sender, System.EventArgs e)
            {
                this.Visible = false;
            }


    Now another doubt, with the visible property false, the FormRegion's content is invisible, but the FormRegion still available, it has to be hidden?



    I'm sorry if the text is difficult to understand, I do not speak English very well and I'm using Google Translator.


    Thank you.
    • Edited by Drausio Wednesday, September 11, 2013 5:26 PM
    Wednesday, September 11, 2013 4:37 PM
  • If each profile has one email account use what I said to use previously, NameSpace.CurrentUser.Address. If Exchange is involved you'll get an Exchange format address.

    Other than FormRegion.Visible about all you can do is to not supply the form region manifest or storage information when requested. That would cause an exception that you can probably handle to ignore.


    Ken Slovak MVP - Outlook

    • Marked as answer by Drausio Thursday, September 12, 2013 12:50 PM
    Wednesday, September 11, 2013 6:08 PM
  • Hi, I would like to thank the help. Managed to get a solution that assisted me well.

    For those who have the same problem, my solution:

    Thanks very much

    public static class Profile
    {
        public static string accountAddress { get; set; }
    }
    
    
    
    private void ThisAddIn_Startup(object sender, System.EventArgs e)
    {
        Profile.accountAddress = this.Application.ActiveExplorer().Session.CurrentUser.AddressEntry.GetExchangeUser().PrimarySmtpAddress;
    }
    
    
    /// <summary> 
    /// Required method for Designer support - do not modify 
    /// the contents of this method with the code editor.
    /// </summary>
    private static void InitializeManifest(Microsoft.Office.Tools.Outlook.FormRegionManifest manifest, Microsoft.Office.Tools.Outlook.Factory factory)
    {
    
    # if DEBUG
        Microsoft.Office.Tools.Outlook.FormRegionCustomAction formRegionCustomActionImpl1 = factory.CreateFormRegionCustomAction();
        formRegionCustomActionImpl1.Name = "formRegionCustomAction1";
        manifest.CustomActions.Add(formRegionCustomActionImpl1);
        manifest.FormRegionName = "Form Region 2 - Not visible";
        manifest.FormRegionType = Microsoft.Office.Tools.Outlook.FormRegionType.Adjoining;
        manifest.Hidden = true;
        manifest.ShowInspectorCompose = false;
        manifest.ShowReadingPane = false;
        manifest.Title = "Form Region 2 - Not visible";
    # else
        if (Profile.accountAddress != "account@domain.com")
        {
    	Microsoft.Office.Tools.Outlook.FormRegionCustomAction formRegionCustomActionImpl1 = factory.CreateFormRegionCustomAction();
    	formRegionCustomActionImpl1.Name = "formRegionCustomAction1";
    	manifest.CustomActions.Add(formRegionCustomActionImpl1);
    	manifest.FormRegionName = "Form Region 2 - Not visible";
    	manifest.FormRegionType = Microsoft.Office.Tools.Outlook.FormRegionType.Adjoining;
    	manifest.Hidden = true;
    	manifest.ShowInspectorCompose = false;
    	manifest.ShowReadingPane = false;
    	manifest.Title = "Form Region 2 - Not visible";
        }
    # endif
    }
    

    • Marked as answer by Drausio Thursday, September 12, 2013 12:48 PM
    • Unmarked as answer by Drausio Thursday, September 12, 2013 12:48 PM
    • Marked as answer by Drausio Thursday, September 12, 2013 12:50 PM
    • Unmarked as answer by Drausio Thursday, September 12, 2013 12:50 PM
    Thursday, September 12, 2013 12:48 PM