Importing Windows Forms (C#), Visual Studio 2012
Solution 1
Tried to reproduce your issue - without success.
Assume that you want to import a Form called YourFormName
. Then you should only add YourFormName.cs
to the project - the rest parts (YourFormName.designer.cs
and YourFormName.resx
) will be added automatically.
My steps:
- Create WinForms project (in my case .Net Framework is 4) in VS2012 (11.0.05727.1 if matters)
- Right-click on projects -> Add -> Existing Item...
- Search for any WinForm with controls (I added two forms created in VS2010 for .NET framework 4 and 3.5)
- With some delay (approx 30-40 seconds), for both cases "Designer" worked as expected and loaded all existed controls/codebehind
Solution 2
Just include the cs file and just wait
for about mintue. No other files required to be added.
This will work.
go to project
> add existing item
select the form myform.cs
file and then click on the add
button. This will import the file in your project.
Matthias
Updated on June 16, 2022Comments
-
Matthias about 2 years
trying to add an existing Windows form into a VS2012 WinForm project, I go "Add/Existing item..." then import: MyForm.cs, MyForm.designer.cs, MyForm.resx
This used to work in earlier versions of VS. (I may have to adjust the namespaces.)
In VS2012 MyForm.designer.cs and MyForm.resx are now not associated with the Form for purposes of the Designer; i.e. they show up as separate file entries in the Solution Explorer, not nested under MyForm. Double-clicking MyForm shows an empty form (no controls) with no error messages. The project compiles and runs OK.
However, when I drag and drop the same files into the project (adjust/rename the namespace), the form files are properly associated with one another and the Designer opens the form fine.
While I now have a solution, can someone highlight what difference is between these approaches, what is the point of having an Add/Existing Item option if it doesn't work, and what is actually going on when dragging the files? Which file (.csproj perhaps?) is responsible for joining the form files? Because it works both ways in earlier versions of VS can I assume this is a bug?
Thanks.