Your Second Outlook Add-in

In my previous post, I showed you how to create a custom task pane that hosted a user control data bound to an external data source. The control enabled you to browse data and then create a sales contact with the currently selected record. Vaguely interesting, yes, but more to the point we successfully extended Outlook and then manipulated and changed an Outlook item based on external data that we were browsing. In this post, I've added a small snippet to get you started on creating an Outlook form region (OFR).

OFRs are great; they allow you to extend your Outlook experience with customized forms that integrated into the various inspectors or forms within Outlook. For example, I could create a custom OFR for a mail message that is dynamically bound to my email properties or I could create a custom OFR for my sales contacts that looks up their address and maps their address for us on the OFR. In this blog post, I'll walk you through a simple OFR and then point you to some additional information that may be helpful for your more extensive OFR development.

OFRs are an artefact of Visual Studio Tools for Office (VSTO) 3.0, which is a component technology within Visual Studio 3.0 that enables you to create Office solutions. To create an OFR, open Visual Studio 2008 and click File, New, Project, and then select the Office node under either Visual C# or Visual Basic. Once you've got your project set up, right-click the Project and click Add New. In the Add New dialog, select Office and then select Outlook Form Region. Provide your OFR with a name and click Add. This kicks off a wizard that walks through the OFR creation process. You can either create a new OFR or import an existing one. Note that you have a number of choices here: i) Adjoining, ii) Separate, iii) Replacement, or iv) Replace All (see the article below for more information on these). Select Separate and click Next.Give your OFR a name and leave the two check-boxes checked.Click Next and then select Mail Message and then click Finish. This will set up and add your OFR to your project.

The OFR will have a couple of critical methods you'll want to pay attention to (double-click the OFR designer to see these methods):


        private void Demo_FormRegionShowing(object sender, System.EventArgs e)




        private void Demo_FormRegionClosed(object sender, System.EventArgs e)




    Private Sub FormRegion1_FormRegionShowing(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.FormRegionShowing


    End Sub


    Private Sub FormRegion1_FormRegionClosed(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.FormRegionClosed


    End Sub

These methods are, similar to other VSTO project shell methods, methods that allow you write constructor and clean-up code for your OFR when it shows and when it is closed. If you go back to the designer view, you can add controls to your OFR. Go ahead and add a combo-box, a label, a button and a web-browser control. In my project, I added "Stocks:" as the label text, added the text "Go" to the button, set the Name property of the button to Go, set the combo-box Name property to cmboStock, and then added five items to the combo-box collection: i) V, ii) MSFT, iii) GOOG, iv) GE, and v) CSCO. You'll want to size the web browser as 1000 x 900. I also changed the Name property of the web-browser control to stockBrowser.

The heavy-lifting, or not so heavy-lifting, is done by our button. You will want to add an event off of the button and then load the page in the web browser based on the user's selection. This is the code that you'll hang off of the button:


        private void Go_Click(object sender, EventArgs e)



            string strMsnURL = "";

            string strStock = cmboStock.SelectedItem.ToString();

            string fullStockURL;


            fullStockURL = strMsnURL + strStock;






    Private Sub Go_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Go.Click


        Dim strMsnURL As String

        Dim strStock As String

        Dim fullStockURL As String


        strMsnURL = ""

        strStock = cmboStock.SelectedItem.ToString

        fullStockURL = strMsnURL + strStock




    End Sub

Once you've done this, you're done with the coding part of the sample. You can hit F5 and build your project.

I like the Separate OFR because it creates a button that enables you to toggle back and forth across default and custom inspector views. And for the above sample, if you create a new mail message you should see a button on your ribbon (name of your OFR), which you can click to view the OFR (see the attached image).

In general, OFRs are pretty exciting because you can host Windows Forms or WPF user controls and of course OFRs (and more widely VSTO) supports LINQ, WF, WCF, etc. This was a simple one to get you started, but you can check out the VSTO Developer Center for more information. Also, I recently published an article with MSDN magazine that provides a more in-depth walkthrough of a custom OFR (this one walks through a Replacement OFR). You can find these links as follows:

1. VSTO Developer Center:

2. MSDN Magazine Article:

Also, as I mentioned in an earlier blog entry the MSPress book Programming Applications for Office Outlook 2007 is a good book for learning about all things Outlook.

Have a great day!



Skip to main content