Поделиться через


How to: Add Windows Forms to Outlook Solutions

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

Applies to: The information in this topic applies to application-level projects for Outlook 2007 and Outlook 2010. For more information, see Features Available by Office Application and Project Type.

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

Getting Started Programming Application-Level Add-Ins

Other Resources

Outlook Object Model Overview