How do you add an existing form to a new project?

后端 未结 21 2199
予麋鹿
予麋鹿 2020-12-13 09:06

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 depen

21条回答
  •  醉话见心
    2020-12-13 09:25

    After doing a lot of testing and failing to correctly recognise the form when added, even though .designer and .resx were copying through when .vb was imported, I found Vidar's solution the best, least hacky fix.

    It appears that if these references are not already in the project (if there are no forms yet), the form is not recognised as a form and is imported as a code module instead.

    • System.Drawing
    • System.Windows.Forms

    These can either be added manually per their solution above, or you can simply

    1. Add a new blank form to the project (this automatically adds the references above)
    2. Add existing form .vb/.cs you want to import (it will now show the form icon in the Solution Explorer and 'View Designer' will be available from context)
    3. Delete the blank form or use it for something else

    This does not require editing any of the VS config files as shown in other answers to the question.

提交回复
热议问题