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. Jessica H 0 Reputation points
    2023-11-15T01:41:02.0666667+00:00

    I had this issue today and found a simple solution, I think, assuming it's the same issue/cause!

    I had a solution of 4 projects and 2 had the same "about" form. I wanted to add it to the new 4th project so I added the existing form, resx and designer files from the first project and fixed a few missing resources and references to them and then it compiled and ran however I couldn't open the form in the designer!

    So I compared the vbproj files between the two projects and saw there was an incomplete section of XML in the new project.

    In the new project it had this single line at the bottom for the resource file:

    <EmbeddedResource Include="frmAbout.resx" />
    

    However in my working project the resource was embedded like this:

    <EmbeddedResource Include="frmAbout.resx">
      <DependentUpon>frmAbout.vb</DependentUpon>
      <SubType>Designer</SubType>
    </EmbeddedResource>
    

    So I copied that into the new .vbproj file and reloaded the project and now it worked!

    (*Actually it was a few more steps since I messed up and copied the wrong resource section at first, in an outside editor... while the project was open. Oops. The form ended up going blank and my main form started getting errors, I had to revert the .vbproj to the version before attempting this and add the about form and resource files again and then edit the vbproj but this time I had to add both the compile section and the resource section! The compile section looked like this:

    <Compile Include="frmAbout.Designer.vb">
      <DependentUpon>frmAbout.vb</DependentUpon>
    </Compile>
    <Compile Include="frmAbout.vb">
      <SubType>Form</SubType>
    </Compile>
    

    So if anyone else has this issue and then messes up like I did, this is how I fixed it lol)

    0 comments No comments

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.