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. Leon Stanley 96 Reputation points
    2022-02-07T07:17:11.673+00:00

    Sounds like you are missing some components for VB.
    In VS choose Tools >> Get Tools and Features.
    Under the Workloads tab >> Desktop and Mobile (5)
    you should need both [Net desktop developments] AND [Universal Windows Platform development] ticked.
    If not you need to select them and download the missing components.
    If you also code in C++ you also need the [Desktop Development with C++] set of components also.

    0 comments No comments

  2. Karen Payne MVP 35,586 Reputation points Volunteer Moderator
    2022-02-07T11:20:22.64+00:00

    I found the item Form2.Designer.vb in my solution folder

    Since Visual Studio first came out, when adding a new item (class, form etc) to a project the default location is the project folder unless you where to prefix the item with a path. So, if you had Solution Explorer opened, right clicked to your project to add the new form and it was created under the solution folder rather than the project folder you need to report this to Microsoft via the submit feedback/bug in the upper right corner of the IDE.

    See the docs for How to add a form to a project (Windows Forms .NET and if this is what you did, report this as a bug.

    https://learn.microsoft.com/en-us/dotnet/desktop/winforms/forms/how-to-add?view=netdesktop-6.0

    But I can't get it to show the visual layout of the form. In the My Project subfolder

    This means either all the form is malformed or you are missing a file.

    I changed the name of the form to frmPsrch, but the title on its tab still said Form2.

    Changing the form name does not change the title, you need to select the form, select form properties and change the title.

    0 comments No comments

  3. Rich Goldberg 161 Reputation points
    2022-02-08T05:10:47.877+00:00

    Thank you all for your suggestions.

    But today was another frustrating day. I tried @Jiachen Li-MSFT ’s suggestions, to no avail. I read @Karen Payne MVP ’s doc on adding a form (although I believe I was already doing it, just via a different route). Finally I gave up and decided to start my frmPSrch from scratch again.

    Before doing that, I looked at the folders involved. Apparently I’m very confused concerning projects and solutions. In my \Repository folder I have an \MM subfolder, which contains nothing but a \Prm subfolder. In \Prm are my frmMain three documents (.Designer.vb, .resx, and .vb), Prm.sln, and a few other things. But -also- included in that folder is a \My Project subfolder. I found the three frmPSrch documents in -that- folder!

    Today, I removed all the Form2 and frmPSrch from both those folders and opened my Prm solution again. I got rid of all references to those two, then followed the instructions for adding a new form to the project. I performed all the steps so that everything now said frmPSrch. This time I added only I textbox to the form, saved it all, then went to test it. In my Sub Main() I added “Dim PSrch As New FrmPSrch”, but got an error because suddenly it doesn’t know what frmPSrch is. I looked in the folders, and once again, all my stuff is in the \Prm folder, except for frmPSrch, which is in its \My Project subfolder! Once again, Visual Studio shows me frmMain, but it won’t show me anything about frmPSrch.

    Any suggestions for restoring my sanity would be greatly appreciated.


  4. Rich Goldberg 161 Reputation points
    2022-02-08T19:05:35.833+00:00

    @Peter Fleischer (former MVP) :
    I opened Repository\MM\Prm\Prm.vbproj . Searching for “frmPSrch” I found
    <Compile Include="My Project\frmPSrch.Designer.vb">
    <Compile Include="My Project\frmPSrch.vb">
    <EmbeddedResource Include="My Project\frmPSrch.resx">
    all residing in MM\Prm\My Project.

    Searching for “My Project” I found
    <Compile Include="My Project\AssemblyInfo.vb" />
    <Compile Include="My Project\Application.Designer.vb">
    <Compile Include="My Project\frmPSrch.Designer.vb">
    <Compile Include="My Project\frmPSrch.vb">
    <Compile Include="My Project\Resources.Designer.vb">
    <Compile Include="My Project\Settings.Designer.vb">
    <EmbeddedResource Include="My Project\frmPSrch.resx">
    <EmbeddedResource Include="My Project\Resources.resx">
    <None Include="My Project\Application.myapp">
    <None Include="My Project\Settings.settings">

    However, when I look at references that do not include a folder name, I find
    <Compile Include="Class1.vb" />
    <Compile Include="frmMain.vb">
    <Compile Include="Module1.vb" />

    It seems to me that the Class1, frmMain, and Modlue1 that I created are the problem here; they should be in the the MyProject subfolder. Do you agree? If so, is it viable to move them to \MyProject and update \Prm.vbproj to reflect that? Or just make copies of what I’ve got and start over again?

    Having just watched a video on solutions and projects, I’m guessing I didn’t start with a blank solution, and that might be the cause here. [I don’t remember exactly how I started, so that’s just a guess.]

    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.