Copying a Form in Visual Basic 2010 Express-VBForums
Results 1 to 6 of 6

Thread: Copying a Form in Visual Basic 2010 Express

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2012
    Posts
    68

    Copying a Form in Visual Basic 2010 Express

    I wanted to copy a complex form I had created because there was another form that was nearly identical. Apparently this is very difficult in VB2010E. I tried a variety of techniques (copying files in windows explorer, editing with notepad to change classname, copying and pasting in the IDE window, etc.). I finally managed to get both forms to appear in my project, but I believe my vbproj file may have become corrupted because I cannot select one of the forms as my app's startup form (see attached). What is wrong here? Is my vbproj or my form corrupted? Is there a proper way to copy a form? When one imports a form, what files are needed (.vb? .designer.vb? .resx?)

    Name:  question_screenshot2.jpg
Views: 855
Size:  94.4 KB

    Note how the form frmCategEnt is not available in the startup form drop-down.

    I really don't want to have to create this form all over again. More importantly, I hope my vbproj file is not corrupted.

  2. #2
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,238

    Re: Copying a Form in Visual Basic 2010 Express

    You can copy a form from 1 project to another, rename it and then copy it back to the original project using Solution Explorer window (right click on the form, copy and right click on another project > paste). If your solution has only 1 project, you can add a new dummy project to it, copy the forms from the valid project to the dummy one, change the form name and class name (for class name, use the form's property window so that VS can properly update all the references). Once you're happy with the changes, copy the forms back to the valid project and delete the dummy one.
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  3. #3

    Thread Starter
    Lively Member
    Join Date
    May 2012
    Posts
    68

    Re: Copying a Form in Visual Basic 2010 Express

    Thanks for the clarification. That seems pretty absurd to me. I appreciate the help with this undocumented "feature" of VB.

    Any suggestions about what to do with my possibly-corrupted VB Project above?

  4. #4
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,241

    Re: Copying a Form in Visual Basic 2010 Express

    You mean you understood that? I was going to suggest Project > Add Existing Item but I'm not sure I should now!

    Whatever way you do it, you'll always have to resolve clashes of names, unreferenced variables, dependent files etc. before the addition can be considered suitable as a starting form.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    May 2012
    Posts
    68

    Re: Copying a Form in Visual Basic 2010 Express

    Quote Originally Posted by dunfiddlin View Post
    You mean you understood that? I was going to suggest Project > Add Existing Item but I'm not sure I should now!
    Unless I'm confused, he has suggested copying a form from my primary project to a different (possibly temporary) project in my VB Solution, renaming the item in question in that other project, and then copying/moving it back to the original project. This seems ridiculously convoluted to me, but it kind of makes sense that the IDE would take care to also copy any connected resources necessary for the form. I'm still not sure exactly what the .vb, .designer.vb, and resx files each represent. I tried adding existing item but for some reason it had problems -- don't recall specifically what they are now, but I think it was name conflicts and then when i try to open the form i get the "something happened" screen.

    Quote Originally Posted by dunfiddlin View Post
    Whatever way you do it, you'll always have to resolve clashes of names, unreferenced variables, dependent files etc. before the addition can be considered suitable as a starting form.
    Will these be reported in the warnings/errors?

  6. #6
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,241

    Re: Copying a Form in Visual Basic 2010 Express

    Quote Originally Posted by sneakyimp View Post
    Unless I'm confused, he has suggested copying a form from my primary project to a different (possibly temporary) project in my VB Solution, renaming the item in question in that other project, and then copying/moving it back to the original project. This seems ridiculously convoluted to me, but it kind of makes sense that the IDE would take care to also copy any connected resources necessary for the form. I'm still not sure exactly what the .vb, .designer.vb, and resx files each represent. I tried adding existing item but for some reason it had problems -- don't recall specifically what they are now, but I think it was name conflicts and then when i try to open the form i get the "something happened" screen.


    Will these be reported in the warnings/errors?
    Yes to the latter. And as kind of an answer to the former, the more complex the form the more challenges it represents. Ideally, you'd only add forms that have been stripped of code or are at least completely self contained.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.