Visual Studio: New form not included in VB.Net project

Rich Goldberg 161 Reputation points
2022-02-06T21:40:59.38+00:00

I'm still new to Visual Studio, and using VS 2022. I was able to create and test several VB.Net modules successfully. I added a new form to the project, changed the form name of "Form1", and all was good. Then I created a new form, which it named Form2. Apparently I told it to create the form, but not as part of the project. I spent hours adding the form components and customizing its attributes. I changed the name of the form to frmPsrch, but the title on its tab still said Form2. That's when I decided something was wrong. I found the item Form2.Designer.vb in my solution folder, made a copy just in case, and renamed the original frmPsrch.Designer.vb . I opened VS again, decided that the best way to include the form was Project / Add Existing Item, and it opened a pane with the VB code. The good news is that all of my items are included, and the values that I set up are all there. But I can't get it to show the visual layout of the form. In the My Project subfolder I found the Form2.Designer.vb, Form2.resx, and Form2.vb files, so I'm hoping the data I need is still there somewhere. Is there a way to get all the form info back into VS as part of my solution?

Developer technologies Windows Forms
Developer technologies VB
0 comments No comments
{count} votes

Accepted answer
  1. Jiachen Li-MSFT 34,221 Reputation points Microsoft External Staff
    2022-02-07T07:01:09.877+00:00

    Hi @Rich Goldberg ,
    I don't know how you created the form outside of project.

    • If you can see it in Solution Explorer, you can just copy it directly into your project.
    • If can't, you can just create a new form "Form2" in your project, then delete Form2.vb and Form2.Designer.vb in the project folder and paste the Form2.Designer.vb, Form2.resx, and Form2.vb files into it.Then Form2 in your project will be replaced with the form you created earlier
      Hope this could be helpful.
      Best Regards.
      Jiachen Li

    ----------

    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

9 additional answers

Sort by: Most helpful
  1. Peter Fleischer (former MVP) 19,341 Reputation points
    2022-02-09T04:50:40.907+00:00

    Hi Rich,
    you should never use File Explorer to move or delete files managed by Visual Studio. All of these changes should be made from the Visual Studio UI, using the context menu (Add existing item, Delete, etc.). Then the vbproj file will automatically be created correctly. To repair a "defective" project, you can create an empty project, create all folders using Visual Studio, then use File Explorer to copy/move all files to the desired folder and finally use Visual Studio with "Add existing Item" add these files. It is important to work with "<asterix>.<asterix>" (all files) in order to see all files.


  2. Rich Goldberg 161 Reputation points
    2022-02-11T05:00:32.63+00:00

    @Peter Fleischer (former MVP) :
    Yeah, that's what I did after your first response. But I did it for items that should not have been copied, and it messed things up. Unlike your wonderful display above, in my final attempt I created two dummy forms with the same names as I already had saved in my project folder. You show the import of the .vb file, but I wouldn't have known which of the three extensions (or all three) to import. So I looked at the folders and simply overwrote those same filenames. I understand your concern, and if it ever happens again (no, No, NO!) I'll do it your way.

    0 comments No comments

  3. Rich Goldberg 161 Reputation points
    2022-02-10T06:14:41.11+00:00

    @Peter Fleischer (former MVP) :
    I took your advice and, after saving the folders containing all my previous attempts, started from scratch with a new repository. I created an empty solution and a new project.

    I created a new folder, \To Be Imported. I believe there are only four pieces I created that need to be imported to the new project: Class1, Module1, frmMain, and frmPSrch. Looking at these items in two of the saved repositories, I decided to use 3 of those items from one saved repository, and 1 from another. Using File Explorer, I copied all the files of those components to the \To Be Imported folder. Here’s what it looked like:
    Directory of C:\To Be Imported

    02/09/2022 11:09 PM <DIR> .
    02/09/2022 11:03 PM <DIR> ..
    02/03/2022 04:15 PM 3,707 Class1.vb
    02/06/2022 01:57 PM 14,715 frmMain.Designer.vb
    02/06/2022 01:57 PM 6,802 frmMain.resx
    02/06/2022 01:57 PM 453 frmMain.vb
    02/06/2022 02:06 PM 18,576 frmPsrch.Designer.vb
    02/06/2022 02:42 PM 116,974 frmPsrch.resx
    02/06/2022 01:56 PM 1,470 frmPsrch.vb
    02/07/2022 11:07 PM 8,915 Module1.vb

    In Visual Studio 2022, with my new project open, pulled down Project, then chose Add Existing Item. I used the <asterisk>.<asterisk> view and selected all the items in the To Be Imported folder, then hit the Add button. All of my items now show up in the Solution Explorer:
    173007-solution-explorer.jpg

    Right-clicking on frmMain.vb and choosing View Code, it shows me just stubs (Private Sub/End Sub) for TextBox1_TextChanged, File_Click, Form1_Load, and SaveToolStripMenuItem_Click. Choosing View Designer for it just shows an empty window. On the other hand, right-clicking on frmMain.Designer.vb and choosing View Code, it shows me real code for the Tool Strip that I created, etc. But there is no View Designer option for this item. All of this is true for frmPsrch as well. The bottom line is that my code is there, but I can’t seem to get a designer view for my imported forms.

    As a test, I added a new form (Form2), and it shows up as Form2.vb, but there’s no Form2.Designer.vb like there is for the ones I imported. Apparently I’m importing something wrong, and I’m hoping someone out there can tell me what that is.

    I’ll spend one more day trying to recover the work I did, and if I can’t, I’ll give up and start over with the knowledge that I’ve gained during this ordeal. I thank you all for your comments and your time.

    0 comments No comments

  4. Rich Goldberg 161 Reputation points
    2022-02-11T03:08:39.893+00:00

    @Jiachen Li-MSFT , @Peter Fleischer (former MVP)

    Success! I used a combination of your suggestions, and very happily didn’t have to start from scratch.

    I started again with a new solution and project. I imported my Class1 and Module1 from my oldest save, where almost everything worked. I then created new forms frmMain and frmPSrch, which are the two forms that have not been working right, with a single text box in each. I saved everything, looked at the folders to see exactly which files got created for my two forms. There weren’t as many as I had thought previously. I went back to my original project and copied only those form files that existed in the current project folder. When I restarted Visual Studio, my designed forms were there and I was truckin’.

    I am most grateful to all who took the time to think about my problem and gave me suggestions. Someday I hope to return the favor.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.