Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

VB.NET: Copy & Paste Form Problem

yauchildchewyauchildchew Member Posts: 19
For a proper program when i try to copy, say Form1 in the Solution Explorer and then paste it into the Project, Copy of Form1 will be listed there with no problem.

Problems arise when i try to RUN the program;
[b]The item "objDebugWindowsApplication1.form1.resources" was specified more than once in the "Resources" parameter. Duplicate items are not supported by the "Resources" parameter. [/b]
this error description always show up but the Program still works as it is.

And when i try to go to the Designer of Copy of Form1, i cant and..
[b]Failed to parse method 'InitializeComponent'. The parser reported the following error 'Error HRESULT E_FAIL has been returned from a call to a COM component.'. Please look in the Task List for potential errors. [/b]
shows up!

So, any idea whats wrong and the fix?

Thanks!

Comments

  • BitByBit_ThorBitByBit_Thor Member Posts: 2,444
    : For a proper program when i try to copy, say Form1 in the Solution
    : Explorer and then paste it into the Project, Copy of Form1 will be
    : listed there with no problem.
    :
    : Problems arise when i try to RUN the program;
    : [b]The item "objDebugWindowsApplication1.form1.resources" was
    : specified more than once in the "Resources" parameter. Duplicate
    : items are not supported by the "Resources" parameter. [/b]
    : this error description always show up but the Program still works as
    : it is.
    :
    : And when i try to go to the Designer of Copy of Form1, i cant and..
    : [b]Failed to parse method 'InitializeComponent'. The parser reported
    : the following error 'Error HRESULT E_FAIL has been returned from a
    : call to a COM component.'. Please look in the Task List for
    : potential errors. [/b]
    : shows up!
    :
    : So, any idea whats wrong and the fix?
    :
    : Thanks!
    :

    Yes. Don't copy within the same namespace. It's not supported.
    What the IDE does is basically this (this is an example that shows how 'ridiculous' copying Form1 becomes behind the scenes):
    [code]
    Class A
    Private x As Integer

    Public Sub PrintX()
    Console.WriteLine(x)
    End Sub
    End Class

    Class A
    Private x As Integer

    Public Sub PrintX()
    Console.WriteLine(x)
    End Sub
    End Class
    [/code]
    You would never think of typing this, because it's obviously dually defined.

    However, by copying this is exactly what happens, just behind the scenes and by merging different files together. But VB.NET does not care about filenames. It merges it all together in the end. Filename ordening is only for the user, but not for VB.

    The solution is to open the Copy of Form1.vb file and change the Class name to something unique. Then also do this for Copy of Form1.Designer.vb *(you'll need to open this file through Windows) and change the Partial Class name to the same name.
    Once this is done, it'll work.


    Best Regards,
    Richard

    The way I see it... Well, it's all pretty blurry
  • yauchildchewyauchildchew Member Posts: 19
    I have tried and it works exactly as how you mentioned! Thanks!
  • myplace311myplace311 Member Posts: 1
    The best way to do this is to

    File > Export Template > export item template > select the form you want to copy > Export template

    Then

    Solution Explorer > Right Click on project header > Add Item > Select exported item template > Rename it as desired > Check it out, all subs and designer completely in tacked without having to do crazy editing!



Sign In or Register to comment.