copy of .net Form

Posted on 2012-09-03
Last Modified: 2012-09-04
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
Question by:Rick Norris
    LVL 18

    Expert Comment

    by:Matthew Kelly
    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
    LVL 18

    Expert Comment

    by:Matthew Kelly
    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.

    Author Comment

    by:Rick Norris
    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
    LVL 39

    Accepted Solution

    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.
    LVL 83

    Assisted Solution

    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.

    Author Closing Comment

    by:Rick Norris
    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

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
    If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
    This video discusses moving either the default database or any database to a new volume.
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now