Bob Heitzman

This should but stone simple but I can't figure it out....

I have an exiting form that is being loaded/referenced by other forms. I what to clone the form to start a new one based on that form. I don't want inheritance, just a new form that contains my work up to that point.

File, Save As... messes up the existing reference. Ditto for changing the form name property.

No help for this in the help file - too simple or impossible

Also - part of the process is most likely adding an existing item to the project. I have tried that with forms created in other projects (copied the files in the project first) but even if I use Add as Link I get a entry in the project that has a child item that normal forms do not have. How do I add and existing set of form files that worked in another project

Give me the answers for VB Express - I'm running VS 2005 with the Vista SP but the steps should be the same (unless Vista version is busted of course.)

Thanks!






Re: Visual Basic Express Edition Copy a Form?

Bruno Yu - MSFT

Bob Heitzman,

I hope the following article on Forms collection can help you with the problem:

How to create a forms collection in Visual Basic .NET or in Visual Basic 2005

http://support.microsoft.com/kb/308537/

Visual Basic .NET or Visual Basic 2005 does not provide a built-in collection for Form objects that are used in a project. This article demonstrates how to build a custom collection class that essentially supports the same functionality as the previous versions of Microsoft Visual Basic.






Re: Visual Basic Express Edition Copy a Form?

Bob Heitzman

I don't want to copy the form in a running program. I want to copy the underlying working files to enhance in the IDE. That is, within a VB project I'd like to take form1.vb and make a duplicate in the IDE to work on without messing up form1.vb.

The save as and other operations does stuff under the covers to the designer code of the form being copied, and other forms that may have references to that form, that prevents a simple copy and paste to a new form.

All I want is to take an existing form, that other forms have a refernce to, and make a copy that no other form references so that it appears in the IDE as a new form. The form that was copied should not be touched and any references to it should still work and not be fixed up to point to the copy.

I've tried to do this in VS 2005 but I wound up with a frmName in the project explorer that had a DIFFERENT name in Intellisense - how weird. The name that appear in the Intelliesense list didn't even appear to be in the project. No form had a property with the name that appeared in the Intellisense list.

Any way - as in the first post - this should be stone simple - I'm probably just missing something basic.





Re: Visual Basic Express Edition Copy a Form?

spotty

The filename in Solution Explorer is a physical filename, Intellisense does not use this name but uses the class name contained in the file. A form is just a class with a user interface, the class is split over a couple of files (frm.vb, frm.designer.vb, frm.resx)

So if you do a save as to save a new copy of you file, then go to this new form and change the name property form to a new name. Then you can add exisiting item and add your original form back to the project.

Then you have two copies of the form with different names both as a file and a form name.





Re: Visual Basic Express Edition Copy a Form?

Bob Heitzman

>So if you do a save as to save a new copy of you file, then go to this new form and change the name property form to a new name. Then you can add exisiting item and add your original form back to the project.

Could someone decode this for me





Re: Visual Basic Express Edition Copy a Form?

spotty

Save as will create a copy of the file but the the copy will be the one refered to in you project.

However if you want both the copy and the original form in the project then you will have to add the original filename to the project.

If you do this you will have a conflict with the underlying name of the form as both are defining the same class name within the files, so you would have to change the name on one of the forms, to resolve the conflict and allow both forms to be in the same project.





Re: Visual Basic Express Edition Copy a Form?

Bob Heitzman

"Save As" - been there done that. Problem with this approach is that if other forms contain a reference to the form being renamed they all get fixed up to point to the new form. This breaks my application as the original form is the one that is expected.

Seems kind of silly such a powerful tool cannot copy a form.




Re: Visual Basic Express Edition Copy a Form?

spotty

Your code will reference the class contained in the file, not the file itself, hence when you add the original back in. You would disambiguate the between the copy and the original and rename the class in one of them.

So the filenames need to be different from an OS point of view.

The classes need to be different from a compiler point of view.

So in order to have both in the same project - you really would need to have different filenames and different form names.

Think when you copy a file in windows it doesnt have the same name it changes it to "Copy Of" the filename. As the compiler doesnt care about the filename it cares about the contents (ie. the class name) this is why you would need to change this.

Should the tool provide a better way to handle copying of forms - probably. This is just the workaround to allow you to make a copy of a form and have both in the project at the same time.





Re: Visual Basic Express Edition Copy a Form?

Bob Heitzman

I think I found a work around - File, Export Template...

I can then Add, New Item... and load from My Templates (may need to scroll down to find).

The saved template appears to be simple .zip file that can be deleted later. This feature may also be an easy way to send someone else a form I've worked on.