How to: Interact with Windows Forms
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer

How to: Interact with Windows Forms

NoteNote

Some code examples in this topic use the this or Me keyword or the Globals class in a way that is specific to document-level customizations, or they rely on features of document-level customizations such as host controls. These examples can be compiled only if you have the required applications installed. For more information, see Features Available by Product Combination.

You can add Windows Forms to your Visual Studio Tools for Office projects the same way you do in other projects in Visual Studio. For more information, see Windows Forms Controls. The following example uses an Excel workbook project.

NoteNote

The dialog boxes and menu commands you see might differ from those described in Help depending on your active settings or edition. To change your settings, choose Import and Export Settings on the Tools menu. For more information, see Visual Studio Settings.

To display a Windows Form

  1. Add a Windows Form to your project. In this example, the Windows Form is called ReportPicker.

  2. Right-click ThisWorkbook in Solution Explorer and select View Code.

  3. Add code to ThisWorkbook_Startup to create a new instance of the form and call the ShowDialog method to display the modal form.

    ReportPicker reportPicker = new ReportPicker();
    reportPicker.ShowDialog();
    
    
    NoteNote

    You can also use the Show method to show a non-modal form.

See Also

Show:
© 2016 Microsoft