Dela via


How to: Interact with Windows Forms

You can add Windows Forms to your Office projects the same way you do in other projects in Visual Studio. For more information, see Windows Forms Controls.

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

The following example uses a document-level project for Excel.

Note

Your computer might show different names or locations for some of the Visual Studio user interface elements in the following instructions. The Visual Studio edition that you have and the settings that you use determine these elements. For more information, see Working with Settings.

To display a Windows Form

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

  2. In the Startup event handler of your project, create a new instance of the form and call the ShowDialog method to display the modal form.

    Dim reportPicker As New ReportPicker
    reportPicker.ShowDialog()
    
    ReportPicker reportPicker = new ReportPicker();
    reportPicker.ShowDialog();
    

    Note

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

See Also

Tasks

Walkthrough: Collecting Data Using a Windows Form

Concepts

Writing Code in Office Solutions

Other Resources

Developing Office Solutions

Programming Application-Level Add-Ins

Programming Document-Level Customizations