How to copy a form

  • Thread starter Thread starter mrmagoo
  • Start date Start date
M

mrmagoo

If I create a form and add add a bunch of controls and code, etc to it, I
can see that Visual Studio adds all of the requisite "creation" code behind
the form.

If I wanted to create a 2nd copy of the exact form, how would I go about
that? Could I just copy the code from the first form, including the
Windows-generated code, and paste it in the code-behind of the 2nd form? I
see that there is a warning not to modify the code-behind using the code
editor, but to instead use the Form Designer. Does that mean what I ask is a
bad idea?

If so, what's the easiest way to add a 2nd form with exactly the same
controls, events, etc?

Thanks.
 
mrmagoo said:
If I create a form and add add a bunch of controls and code, etc to it, I
can see that Visual Studio adds all of the requisite "creation" code behind
the form.

If I wanted to create a 2nd copy of the exact form, how would I go about
that? Could I just copy the code from the first form, including the
Windows-generated code, and paste it in the code-behind of the 2nd form? I
see that there is a warning not to modify the code-behind using the code
editor, but to instead use the Form Designer. Does that mean what I ask is a
bad idea?

If so, what's the easiest way to add a 2nd form with exactly the same
controls, events, etc?

Thanks.

No, your way will work fine. You could also just copy the .vb files for
it and add it to your new project. The warning is just, a warning, you
can make changes but if you do something incorrect the designer might
not work. Make sure to change the class name once you copy it.

Chris
 
Thanks!

Chris said:
No, your way will work fine. You could also just copy the .vb files for
it and add it to your new project. The warning is just, a warning, you
can make changes but if you do something incorrect the designer might
not work. Make sure to change the class name once you copy it.

Chris
 
Everytime I try your approach, I seem to screw up the designer code somehow.
I have reverted to creating a new form then copying all the controls to it.
 
I just do it by copying and pasting the form, in the solutions explorer in
the designer. You just need to change the class name and the form name in
the initialisation code (it will come up as a compiler error so it's easy to
find).

HTH
Simon

--
================================
Simon Verona
Dealer Management Service Ltd
Stewart House
Centurion Business Park
Julian Way
Sheffield
S9 1GD

Tel: 0870 080 2300
Fax: 0870 735 0011
 
Back
Top