copy of .net Form

Hello experts.

I have a form within my UI that contains some basic information; however, it comprises approx 14 input text boxes, various labels, and 4 checkboxes.  This basic functionality needs to be used on approx 27 different "screens"; hence, my objective is to try to copy the basic form, and then add additional functionality on the added forms....

BEFORE I tried to just do a copy and paste, and then re-name the copied form, I did do a backup!!

Very glad I did, I get numerous errors when this is tried.....  Hopefully this should be rather straightforward, but I am just lost....

If there is another approach that can accomplish the same, and would conform to best practices, PLEASE PLEASE point me in the right direction.....  I can see that I may be creating a monster because at some point, the basic functionality I have already designed may change....  Then I'll have about 27 different places to make changes!!!

Using vb .net 2010

Thanks in advance,
Rick Norris
Rick NorrisAsked:
Who is Participating?
appariConnect With a Mentor Commented:
you can try using form inheritance. create a base form and inherit all other forms from this base form and extend them depending on your requirements. all the controls and code in base form is common to all child forms.

Check the following walkthrough

in the walkthrough they are using a class library and using the form in class library as the base form. you can use existing form in your current project as base form.
Matthew KellyCommented:
In .net you can setup User Controls:

Your user control would have the 14 fields

The 27 pages that used those fields would call that control

That is by far the best way to do it if they will be the same
Matthew KellyCommented:
The added functionality you can do by passing an enumeration (Make a parameter called something like formType and then pass a different value on each page) to the control that dictates what changes.

This way the basic structure is always the same, and the tweaks that need to be changes can just be done based on a case statement in the control.
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

Rick NorrisAuthor Commented:
I just took a quick look at the link you provided.....  I may just not understand....  reference is to user control in  I'm using windows forms....  Will be a single user desktop application????

Rick Norris
CodeCruiserConnect With a Mentor Commented:
You can still use User Controls in Winforms. Or you can use inheritence as suggested but if you still want to copy and paste forms then following should work.

Copy and paste 3 form files in Windows Explorer


Rename all 3 copied files to your new form name


Then open the first two files (.vb) in note pad and you should see something like

Public Class MyForm

in both files. Change it to

Public Class MyNewForm

in both files.

After that, in VS, right click on project in solution explorer and click "Add Existing Item". Then select all three files and click Add.
Rick NorrisAuthor Commented:
Code Cruiser....  You answered the question as originally posed.  Even though I plan on using inheritance as suggested by appari, you info will be valuable to me in the future.  Always wondered "how" to accomplish the copy.

Appari....  Thanks for the insight, and a "kick in the head"....  reminded me of the Lothka book I read several years ago on VB6...  Rockford gave a very succinct example of using a base form.  I will be using your suggestion because after I reviewed your links, and pulled out my old VB6 book, it seems to be the most logical solution to my problem, and will keep me from going crazy when things change (as they always do)!

Thanks again guys!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.