Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I add my new User Control to the Toolbox or a new Winform?

I have an existing library (not a Winforms application) that supplies some Winforms to a bona-fide Windows application. Within this library, I would like to create a User Control to group some controls together. To accomplish this, I right-clicked, Add, User Control and dragged some controls onto the new User Control.

So far, so good. The User Control even has the requisite User Control icon. But dragging the new User Control from the Solution Explorer to a new blank Winform does not work (I get a circle with a line through it), and dragging it over to the Toolbox doesn't work either (even though I get a + sign when I drag it over the Toolbox).

Is there some sort of XML magic or something else I'm missing to make this work?


Note: I had some problems with Visual Studio 2008 that I managed to fix by following the workarounds that can be found here. I am now able to get User Controls I added to my existing project into the toolbox by simply rebuilding the project.

like image 585
Robert Harvey Avatar asked Jan 19 '12 18:01

Robert Harvey


People also ask

How do I add a new control to a form?

Adding controls to the form is an easy task, what you need to do is drag a control from the toolbox and drop it onto the form or draw it on the form. You can drag the control around the form and you can also resize it easily.


1 Answers

Assuming I understand what you mean:

  1. If your UserControl is in a library you can add this to you Toolbox using

    Toolbox -> right click -> Choose Items -> Browse

    Select your assembly with the UserControl.

  2. If the UserControl is part of your project you only need to build the entire solution. After that, your UserControl should appear in the toolbox.

In general, it is not possible to add a Control from Solution Explorer, only from the Toolbox.

Enter image description here

like image 75
dknaack Avatar answered Sep 24 '22 02:09

dknaack