Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding a user control using Windows Form designer

This is probably an incredibly obvious question, but I just can't figure it out.

I have a Windows Form managed by the form designer. I'd like to include a custom user control, also managed by the form designer. But I'm unable to get the custom control to show up in the Toolbox, even if I try manually adding it under the "Choose Items..." dialog.

Both form and control are in the same assembly. I've tried separating the control into a separate assembly in order to follow the instructions here to the letter, to no avail. I'm also using C++/CLI, if that changes anything.

Is there an attribute or such I should be setting to my control in order for it to appear in the Designer Toolbox?

like image 671
Camille Avatar asked Jul 08 '10 23:07

Camille


People also ask

How do you add a control into a form?

Add the control by drawingSelect the control by clicking on it. In your form, drag-select a region. The control will be placed to fit the size of the region you selected.

Which method is used to put the user control on the form?

Add your control library dll=>Select dll file and click on open button. Here you can see your user control library has been added=>after that click ok. After that you can see your control inside tets tab: After adding control in tool box you can drag and drop control in your form where you want to use this control.

What is a user control in Windows Forms?

A UserControl is a collection of controls placed together to be used in a certain way. For example you can place a GroupBox that contains Textbox's, Checkboxes, etc. This is useful when you have to place the same group of controls on/in multiple forms or tabs.


2 Answers

Yes, there is one. The only one I'm aware of that prevents a control from showing up in the toolbox if the class is in the same project. Tools + Options, Windows Forms Designer, General, AutoToolboxPopulate should be set to True. The default value.

like image 178
Hans Passant Avatar answered Oct 11 '22 07:10

Hans Passant


In the "choose items" dialog, go to ".NET Framework" tab, your control should be there

If you are from a different project, you need to add a Reference to your project first. (or dll)

In the solution explorer, right click on your project name, click add references

then you should be able to add a .NET reference to your project containing the user control

like image 20
Eric Avatar answered Oct 11 '22 06:10

Eric