Copy a form (for reuse) in a project?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
Is it possible (w/o generating a gazillion errors) to copy a form in VS
2005 so that it can be modified and reused. In other words, I have a form,
alot of which I wish to use in a different form. An no, I don't want to
inherit it. I just want to steal the layout and add and remove a few other
pieces. Any easy way to do this?
 
I am not sure if this is what you mean, but you can drag and drop several
controls at once from a form in one VS session to a form in another VS
session. I would guess that you can copy and paste too, but I always drag
and drop. And, of course, you can copy and paste the associated code (but
that's a separate operation).

Bob
 
That would be waste of time as everytime you do that the controls will take
default name like textbox1, button1, button2, and if you copy and paste the
code behind it wont recognise objects associated.
 
I'm pretty sure that what I did before was copy the files making up the form
to new files in the same directory. You can then add them to your project
with "add exisiting...". You will need to change the class names in the
files added, but it seemed painless to me.
 
Terry,

For controls, don't Copy them, Cut them and Past them back. I mostly make a
dummy form copied outside the designer to do that from, which gives me a
more secure idea.

Cor
 
Select the form in Solution Explorer, right-click and hit Copy. Then, select
the project in Solution Explorer, right-click and hit Paste. Before opening
the newly created copy, hit View Code in Solution Explorer and rename the
class.
That's it.
 
Ok, this *ALMOST* did it! One important step you left out - exclude the
original form from the project and then open the code behind and rename the
class. Else, it gets renamed in both forms, leaving you with the same
problem of 2 classes with the same name in the project. I had tried all the
of the methods mentioned in the thread, this seems the best if you want to
keep some of the code behind, data bindings etc.

Thanks,
 
This doesn't happen (to me) if I just simply rename the class directly in
the code editor (as I described). DON'T do a Refactor! Symbolic Rename...
because, yeah, that will do what you describe.

Terry said:
Ok, this *ALMOST* did it! One important step you left out - exclude the
original form from the project and then open the code behind and rename
the
class. Else, it gets renamed in both forms, leaving you with the same
problem of 2 classes with the same name in the project. I had tried all
the
of the methods mentioned in the thread, this seems the best if you want to
keep some of the code behind, data bindings etc.

Thanks,
 
Ok, got it. You edited the name as opposed to right clicking and 'renameing'
the class name.
Thanks again,
 
Yup. Edit the name directly. The beauty of it is that all the code behind
(partial classes) get renamed too. You only need to do a full "refactor" if
that's... well.... if that's what you want to do. :)

So the steps are:
Select the form in Solution Explorer, right-click and hit Copy. Then, select
the project in Solution Explorer, right-click and hit Paste. Before opening
the newly created form, hit View Code in Solution Explorer and rename the
class *directly* in the code editor (DON'T do right-click->rename). That's
it.

P.S.
This doesn't work as elegantly for webforms (though the steps are similar).
But, then the ASP.NET IDE Designer team have never really done a great job
with anything IMHO.


Terry said:
Ok, got it. You edited the name as opposed to right clicking and
'renameing'
the class name.
Thanks again,
 
Back
Top