[Last Call] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 418
  • Last Modified:

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 Norris
Rick Norris
2 Solutions
Matthew KellyCommented:
In .net you can setup User Controls: http://msdn.microsoft.com/en-us/library/fb3w5b53(v=vs.100).aspx

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.
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 ASP.net.....  I'm using windows forms....  Will be a single user desktop application????

Rick Norris

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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.
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!

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now