0

I previously created a windows form in a vb.net project but now I realized I can use this form in various other projects. Instead of copying the code to every project I want to use it in, I'm trying to create a new project, copy the code to this new project, and reference the new project anytime I want to use the form.

I created the new blank windows form project, copied the vb, resx, and designer files over to it. Then I opened the new solutions folder and selected "Add existing item" and selected the pre-existing vb file. I added references to System.Windows.Forms and System.Drawing to remove "Type 'Button' is not defined" errors but I'm still getting errors that "Event 'Click' cannot be found". Also, when I try opening the designer file I get this error: designer error

I've tried following previous answers concerning how to copy forms to new projects but still haven't been able to figure it out. I don't have much experience working with multiple projects and solutions so I'm probably making a simple mistake but I can't seem to find any other answers directly related to this.

lmac02
  • 3
  • 3
  • Why not use a template? See [How to: Create project templates](https://learn.microsoft.com/en-us/visualstudio/ide/how-to-create-project-templates?view=vs-2022), [Create custom project and item templates](https://learn.microsoft.com/en-us/visualstudio/extensibility/creating-custom-project-and-item-templates?view=vs-2022), and [How to: Create item templates](https://learn.microsoft.com/en-us/visualstudio/ide/how-to-create-item-templates?view=vs-2022) – Tu deschizi eu inchid Mar 17 '23 at 15:40
  • @user09938 because I want to be able to make updates to the form in the future which will take place in all projects that I use the form in. – lmac02 Mar 17 '23 at 16:09

1 Answers1

0

You should not be copying anything. What you should have done is right-clicked the new project and selected Add - Existing Item, then selected the VB file for the form. That would have added the form to the project with all the required parts.

jmcilhinney
  • 50,448
  • 5
  • 26
  • 46
  • Thank you, I had initially tried that but was getting errors. The problem was that I was selecting Class Library instead of Windows Form. – lmac02 Mar 17 '23 at 15:59