Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have never been able to successfully add a Form from an existing file to a new project.

I read on a blog that you add just the *.cs file and the dependencies come in. Well, I tried this and the file did dragin and associate the *.designer and *.resx files. But, the Form icon does not display. Instead, the file looks like a normal *.cs file image. And, when I double click the file I get the code behind instead of the form object.

Is it possible to add existing Forms and get them properly recognized?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
163 views
Welcome To Ask or Share your Answers For Others

1 Answer

After some more research I discovered the source of the issue. It is correct that all one has to import is the *.cs file. The caveat lies in the project type. If working in a Class Library project, another step must be performed.

  1. Add a reference to System.Windows.Forms.dll and System.Drawing.
  2. Import the *.cs file

Notes:

A. The files are only properly recognized after I performed these steps and then tried to open the file. Suddenly VS "wakes up" and fixes the files.

B. Order of the steps does not matter. If you already imported *.cs files, just fix the references.

C. If one is missing other references e.g. DevExpress or other 3rd party control imports), the *.cs files will not display properly until this has been resolved.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...