Adding an Existing Windows Form to Another Project

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:
Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of

kubernetes logging

Kubernetes Logging: What You Need to Know

Kubernetes from Google is one of the most popular open-source and free container management solutions made to make managing and deploying applications easier. It has a solid architecture that makes