Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use a UserControl from the same project without making a DLL?

I made a User Control and already was able to use it by adding it to a form in the C# code. The User Control is in the same VS2005 Project as the main form.

The problem is that I can't see the User Control in the gui editor ([Design] window) with this implementation. I tried many things but I wasn't able to add the user control to the real form desing.

I read some things about making a control lib dll and then add this dll to the toolbox but I don't want to have an additional project and an additional binary file.

How can I use a User Control in an form Design, if both are in the same VS Project? I think somehow this should be possible?

Edit 1:

Sorry I have Visual Studio 2005 not 2010

like image 859
fpdragon Avatar asked Feb 25 '11 08:02

fpdragon


2 Answers

It's certainly possible to use a UserControl in design mode when it's part of the same project.

Do note, however, that it will only show up in your toolbox if you have enabled the "AutoToolboxPopulate" setting. Go to the "Tools" menu and select "Options". Expand "Windows Forms Designer", and click on "General". Make sure that the "AutoToolboxPopulate" property is set to True. When you rebuild your solution, your UserControl should show up at the top of your toolbox, ready to add to your form.

Alternatively, you can add the UserControl to your toolbox manually. To do that, right-click on your toolbox and select "Choose Items" from the context menu. Navigate to your control, ensure that it is checked in the list, and click "OK".

In the event that an exception is thrown (like MacX mentioned), you will still be notified by the designer. The control will still show up in the toolbox, and you'll still be able to attempt to add it to your form.

like image 59
Cody Gray Avatar answered Sep 22 '22 03:09

Cody Gray


As APShredder already mentioned the control should automatically appear in the toolbox. If it doesn't check your Visual Studio Settings:

Tools - Options - Windows Forms Designer - General - AutoToolboxPopulate - True

For further informations just read the Walkthrough in the MSDN.

like image 28
Oliver Avatar answered Sep 26 '22 03:09

Oliver