Click here to Skip to main content
15,911,306 members
Please Sign up or sign in to vote.
1.22/5 (2 votes)
See more:
hi
I have created a User control and compiled the solution.

After compilation in Tool Box, that control is comming.

But when I drag drop to the form, its showing error message: "Failed to load toolbox item 'controle name' it will be removed from the toolbox. "

... and now it will be removed from the ToolBox too.

What is the problem or what is the solution?

Is that a bug of VS2013? Beacause if I create a new project, I design the user control first, and then add dll project. I can drag the control into my form. There is nothing wrong with it? That's weird.
Posted
Updated 21-Jul-20 17:28pm
Comments
Stephen Hewison 3-Jun-14 7:33am    
My advice would be to start with an empty control. Then move the functionality bit by bit from your broken control to the empty one. Testing each time until it stops working.

... June 5 edit ... based on research that indicates that Visual Studio Express does not have the "Windows Forms Control Library" template ...

Assuming you are using: Visual Studio Express 2013 for Windows Desktop, try this:

1. Open New Project, Select a Project Type of 'Class Library'

2. Manually add the references to System.Windows.Forms and System.Drawing and any other references your UserControl requires

3. Add a UserControl: design it, code it.

4. When you compile/save this Project it will create a .dll

To re-use the UserControl in a new WinForms Application Project:

1. Select a ToolBox Tab, context-select "Add New Item"

2. Choose Browse: navigate to the Project of type Class Library where you created the UserControl

3. find the compiled .dll for that Class Lbrary Project: select it: hopefully it will appear in the ToolBox


... end June 5 edit ...

Checklist:

0. the UserControl has a parameterless constructor ?

1. you created the UserControl with no indirect dependencies on other files, dll's, Controls, Forms, etc. ?

2. you created the UserControl as a Project of Type "Windows Forms Control Library" ?

3. you created a new WinForms project where you wanted to re-use the compiled UserControl where:

a. you context-clicked on the ToolBox in some existing Tab, selected 'Add New Item' and then browsed in the selector dialog Form to the UserControl dll ?

b. the UserControl now appears in the ToolBox ?

4. did you register/install the Assembly of the UserControl ? (if you expect the Control to persist in the ToolBox every time you open a new project) ... I suspect this is not relevant to you, but, if it is, see: [^]
 
Share this answer
 
v4
Comments
Water1988 3-Jun-14 17:53pm    
Thank you for your answer.

0. Yes, the UserControl has a parameterless constructor.
1. Yes, it just a UserControl, I didn't add any my own code.
2. No, I create it from a winForm project. I use vs2013 express. It doesn't have the type of "Windows Forms Control Library", but I add the item "User Control", It shouldn't be a problem.
3. No, when I rebuild the project, It has already been the toolbox. I just want use it in one project.
4. I don't know what you are saying. I just want use that User Control in one project. I don't want to use it everytime.
BillWoodruff 4-Jun-14 5:57am    
Is the version of Visual Studio Express you have installed "Visual Studio Express 2013 for Windows Desktop" ?
Water1988 4-Jun-14 12:09pm    
Yes, of course.
BillWoodruff 4-Jun-14 10:27am    
Please look at my revised answer for a possible solution.
Water1988 4-Jun-14 12:31pm    
It works. Thank you.
It's not a VS Bug - I use UserControls a lot, and it's normally because code in your parameterless Constructor is throwing an exception. Either comment out the constructor code and slowly add it back, or create an instance at run time and use the debugger to find out why it's failing.
 
Share this answer
 
Comments
Water1988 3-Jun-14 17:43pm    
Thank you for your answer. The constructor didn't throw any exception. I don't know how to add a control into the form. What should I do?
Water1988 4-Jun-14 0:58am    
There is no wrong in my code. All of it works. I create an instance at run time, and it showes. nothing wrong. It just can't drag.
This has something to do with 64BIT projects, if I remember correctly, the toolbox only supports 32bit.
 
Share this answer
 
Comments
CHill60 22-Jul-20 4:43am    
You didn't remember fully, it's just a bit of a faff.
Some detail here. x64 Class Library of User Controls??[^]
Not my downvote.
rahul-techie 18-Nov-20 6:16am    
Really Thanks :)
just clean and rebuild the project
 
Share this answer
 
Comments
Vladimir Glueck 17-Sep-19 3:59am    
Sometimes the simplest is the best. This one worked for me.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900