Adding an Existing Windows Form to Another Project

Adding an existing Windows Form in VS.Net 2003 means adding two files?for example, a MyForm.cs file with C# code and an XML-based MyForm.resx assembly resource file. In VS.Net 2005, there is a third MyForm.Designer.cs file with the partial class that includes the Windows Form Designer generated code. To add it, open the target solution in VS.NET, right click the project name in the Solution Explorer window, select Add and then Add Existing Item in the context menu, select the above mentioned files in the Add Existing Item dialog box and click the Open button. Generally, you can select only the MyForm.cs file. The selected and associated files are copied to the target project directory. If you prefer to add just the links instead of the separate files, click the drop-down button on right side of the Open button and select Link File.

If your target project has references to these two .NET assemblies: System.Windows.Forms.dll and System.Drawing.dll, as it takes place for a Windows Application project or a C# Class Library that already has a Windows Form, the VS.NET Designer knows that the added file is a Windows Form, opens it, and you won’t have problems working with it.

However, if your target is a C# Class Library that does not have the two above-mentioned references, after you double click the MyForm.cs file name in the Solution Explorer window, the file is opened with the C# Editor instead of VS.NET Designer. You may also notice that the Windows Form file icon for this file is substituted with the Class file icon.

The added Windows Form is shown in the C# Editor instead of the VS.NET Designer because this is default VS.NET behavior when the target .CSPROJ file is updated on the base of limited information available in this circumstance. That means that the value of the SubType attribute (VS.NET 2003) or the content of the SubType tag (VS.NET 2005) for the file in the target .CSPROJ project file will not be set to “Form”?which is required to recognize the correspondent file as a Windows Form.

An analysis of different scenarios of adding an existing Windows Forms to other projects brings us to the following rule: make sure that references to the System.Windows.Forms.dll and System.Drawing.dll assemblies exist in your target project before adding an existing Windows Form. VS.NET recognizes that the file you want to add is a Windows Form and accordingly updates the target .CSPROJ project file, thus eliminating the problem.

Share the Post:
Share on facebook
Share on twitter
Share on linkedin


The Latest

microsoft careers

Top Careers at Microsoft

Microsoft has gained its position as one of the top companies in the world, and Microsoft careers are flourishing. This multinational company is efficiently developing popular software and computers with other consumer electronics. It is a dream come true for so many people to acquire a high paid, high-prestige job

your company's audio

4 Areas of Your Company Where Your Audio Really Matters

Your company probably relies on audio more than you realize. Whether you’re creating a spoken text message to a colleague or giving a speech, you want your audio to shine. Otherwise, you could cause avoidable friction points and potentially hurt your brand reputation. For example, let’s say you create a

chrome os developer mode

How to Turn on Chrome OS Developer Mode

Google’s Chrome OS is a popular operating system that is widely used on Chromebooks and other devices. While it is designed to be simple and user-friendly, there are times when users may want to access additional features and functionality. One way to do this is by turning on Chrome OS