Files
docs-desktop/dotnet-desktop-guide/net/winforms/forms/how-to-add.md
T
Andy De GeorgeandGenevieve Warren 184e6c9a0c Initial publish of WinForms for .NET 5. (#96)
* Migrate inprogress winforms contnet from docs

* Fix preview note

* Fix vb code

* Minor fixes to keyboard articles

* Minor adjustment to overview

* Test redirects for 4.0 -> 5.0

* adjust links

* Add mouse input section winforms (#81)

* Update projects to .NET 5

* Update keyboard desc

* Finish mouse events

* Add remaining mouse articles;code

* finish mouse input

* minor fixes

* Remove branch restriction (#82)

* Update build-validation.yml (#84)

* Update build-validation.yml (#85)

* Fix vb proj

* Add WinForms tutorial (#91)

* redirect between overview

* New create an app tutorial

* Fix markdown

* Fix preserve view setting

* Add forms articles (#93)

* Add forms articles

* Fix warnings

* Winforms publish (#95)

* Prep TOC for publish

* Updated date

* Automatic how-to topic type

* Update desc/headers

* Fix links

* Fix build errors

* Add preview note

* Update toc landing page

* Convert old style project files

* update download links

* Apply suggestions from code review

Co-authored-by: Genevieve Warren <[email protected]>

* Adjust number key

* Update dotnet-desktop-guide/net/winforms/overview/index.md

* Try toc position task via bookmark

* Improve images

* Remove sentence

* File redirects

Co-authored-by: Genevieve Warren <[email protected]>
2020-10-28 10:44:16 -07:00

2.7 KiB

title, description, ms.date, helpviewer_keywords
title description ms.date helpviewer_keywords
Add a form to a project Add a new form to a .NET Windows Forms project in Visual Studio 10/26/2020
Windows Forms, create add form

How to add a form to a project (Windows Forms .NET)

Add forms to your project with Visual Studio. When your app has multiple forms, you can choose which is the startup form for your app, and you can display multiple forms at the same time.

[!INCLUDE desktop guide under construction]

Add a new form

Add a new form with Visual Studio.

  1. In Visual Studio, find the Project Explorer pane. Right-click on the project and choose Add > Form (Windows Forms).

    :::image type="content" source="media/how-to-add/right-click.png" alt-text="Right click solution explorer to add new form to windows forms project":::

  2. In the Name box, type a name for your form, such as MyNewForm. Visual Studio will provide a default and unique name that you may use.

    :::image type="content" source="media/how-to-add/new-form-dialog.png" alt-text="Add item dialog in visual studio for windows forms":::

Once the form has been added, Visual Studio opens the form designer for the form.

Add a project reference to a form

If you have the source files to a form, you can add the form to your project by copying the files into the same folder as your project. The project automatically references any code files that are in the same folder or child folder of your project.

Forms are made up of two files that share the same name: form2.cs (form2 being an example of a file name) and form2.Designer.cs. Sometimes a resource file exists, sharing the same name, form2.resx. In in the previous example, form2 represents the base file name. You'll want to copy all related files to your project folder.

Alternatively, you can use Visual Studio to import a file into your project. When you add an existing file to your project, the file is copied into the same folder as your project.

  1. In Visual Studio, find the Project Explorer pane. Right-click on the project and choose Add > Existing Item.

    :::image type="content" source="media/how-to-add/existing-right-click.png" alt-text="Right click solution explorer to add existing form to windows forms project":::

  2. Navigate to the folder containing your form files.

  3. Select the form2.cs file, where form2 is the base file name of the related form files. Don't select the other files, such as form2.Designer.cs.

See also