Weird UserControl behavior

A

Adam Biser

My apologies if this has been discussed before, but using Google and
also searching the newsgroup has not given me any insight to this problem.

I'm experiencing some strange behavior when I copy and paste a
usercontrol. What happens is that the controls inside the usercontrol
are being created on the form in addition to the copy of the usercontrol.

I'm using VS 2008 Pro, v9.0.21022.8 with .NET 3.5.

Here's how I can duplicate the problem:
1) Create a new Windows Application project.
2) Add a User Control class to the project
3) Add a Component class to the project
4) Change the Component class to inherit from System.Windows.Forms.TextBox.
The IDE will complain that the class already inherits from Component.
Change it so it inherits from TextBox instead.
5) Build
6) Add the Component to the User Control
7) Build
8) Add a User Control instance to the Form
9) Copy the User Control you just added.
10) Paste another instance to the form.

Now you should see the expected user control duplicate. However, check
out the control drop down list in the properties browser window. When
you drop down the list you should see (using the default names)
- Component11
- Form1
- UserControl11
- UserControl12

Why is Component11 there? All I did was copy UserControl11 and paste it
as UserControl12. Why does the User Control's internal component get
copied and becomes an external copy on the form. I find that I actually
have to delete these extra components.

Now if you copy/paste the second UserControl (the one you made with the
first paste), you'll get TWO extra controls (assuming you didn't delete
the first extra one).
- Component12
- object_6e47ae7a_3951_45fe_8305_9870c2cff6fe (or some similar name)

Am I neglecting to do something? Any information pointing me in the
right direction would be helpful.

Thanks
 
R

rowe_newsgroups

My apologies if this has been discussed before, but using Google and
also searching the newsgroup has not given me any insight to this problem..

I'm experiencing some strange behavior when I copy and paste a
usercontrol.  What happens is that the controls inside the usercontrol
are being created on the form in addition to the copy of the usercontrol.

I'm using VS 2008 Pro, v9.0.21022.8 with .NET 3.5.

Here's how I can duplicate the problem:
1) Create a new Windows Application project.
2) Add a User Control class to the project
3) Add a Component class to the project
4) Change the Component class to inherit from System.Windows.Forms.TextBox.
The IDE will complain that the class already inherits from Component.
Change it so it inherits from TextBox instead.
5) Build
6) Add the Component to the User Control
7) Build
8) Add a User Control instance to the Form
9) Copy the User Control you just added.
10) Paste another instance to the form.

Now you should see the expected user control duplicate.  However, check
out the control drop down list in the properties browser window.  When
you drop down the list you should see (using the default names)
- Component11
- Form1
- UserControl11
- UserControl12

Why is Component11 there?  All I did was copy UserControl11 and paste it
as UserControl12.  Why does the User Control's internal component get
copied and becomes an external copy on the form.  I find that I actually
have to delete these extra components.

Now if you copy/paste the second UserControl (the one you made with the
first paste), you'll get TWO extra controls (assuming you didn't delete
the first extra one).
- Component12
- object_6e47ae7a_3951_45fe_8305_9870c2cff6fe (or some similar name)

Am I neglecting to do something?  Any information pointing me in the
right direction would be helpful.

Thanks

If you believe this is a bug you should report it to the .NET
development teams using http://connect.microsoft.com/

Thanks,

Seth Rowe [MVP]
http://sethrowe.blogspot.com/
 
R

rowe_newsgroups

Thanks for pointing me at that site.  After digging around there awhile
and not finding anything, I have posted it as a bug report.

Adam

Sorry I couldn't have been more help - but from experience when it
comes to bugs there's not much more you can do except file a bug
report.

Thanks,

Seth Rowe [MVP]
http://sethrowe.blogspot.com/
 
A

Adam Biser

rowe_newsgroups said:
Sorry I couldn't have been more help - but from experience when it
comes to bugs there's not much more you can do except file a bug
report.

Thanks,

Seth Rowe [MVP]
http://sethrowe.blogspot.com/

I wasn't sure if it was a bug or if I was doing something wrong. Since
searching yielded no results, I thought it must be what I'm doing or not
doing.

Thanks again for pointing me in the direction of that site,
Adam
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top