Share via


How to: Add Windows Forms to Outlook Solutions

Applies to

The information in this topic applies only to the specified Visual Studio Tools for Office projects and versions of Microsoft Office.

Project type

  • Application-level projects

Microsoft Office version

  • Outlook 2003

  • Outlook 2007

For more information, see Features Available by Application and Project Type.

This example adds a Windows Form to a Microsoft Office Outlook project and displays the form to the user.

To add a Windows Form to an Outlook add-in solution

  1. On the Project menu, click Add Windows Form.

  2. In the Add New Item dialog, select Windows Form. Name the form MainForm and click Add.

  3. Add a button to the form.

  4. Double-click the button to add a Click event handler to the code and open the code view.

  5. Add the following code to the Click event handler of the button.

    Me.Close()
    
    this.Close();
    
  6. In Solution Explorer, double-click ThisAddIn.vb (in Visual Basic) or ThisAddIn.cs (in C#) to open the code file. Add the following code to the ThisApplication_StartUp event handler.

    Dim mainForm As New MainForm()
    mainForm.ShowDialog()
    
    MainForm formMain = new MainForm();
    formMain.ShowDialog();
    
  7. Press F5 to build and run the solution.

See Also

Concepts

Outlook Object Model Overview

Getting Started Programming Application-Level Add-Ins