User Controls not showing up in the toolbox

前端 未结 29 2160
暗喜
暗喜 2020-12-13 12:21

I have some UserControls that I created in ProjectA. I have ProjectB that has a windows form that I want to put the controls on. Both of these projects are in a single sol

相关标签:
29条回答
  • 2020-12-13 12:34

    When I tried to add my UserControl to the toolbox (right click toolbox, choose items, select my DLL) it would display a message saying there were no controls in my DLL.

    Anyway, the problem was solved, by trying to create a form in my DLL in VS and adding the UserControl. An error message displayed saying there was no default constructor

    public UserControl() {
    ...
    }
    

    The designer needs this because it can't know what valid arguments are. Once I added a blank constructor to the UserControl it was added to the toolbox without issue.

    0 讨论(0)
  • 2020-12-13 12:35

    I had the same problem. After a lot of googling I did not find anything, but by chance I found out that if you click on the toolbox while you are in the same project that you have created the user control in, and check "show all", then a group with the same name as your project will appear at the top of toolbox which you can find your user control in. Now you can add your control on your desired form!

    0 讨论(0)
  • 2020-12-13 12:35

    If you still can't find why your vstudio toolbox is not populated with your usercontrols. Then you can debug vstudio with another visual studio. Here you can find how.

    0 讨论(0)
  • 2020-12-13 12:36

    What I usually do is create a new tab and add the exe/dll to that tab... Not too comfortable with that solution because of the load time and general hassle.

    A friend showed me a way to speed this up. Instead of having to click "Choose Items..." in the toolbox,etc, for each new control you make - You can create a file named MyCustomControls and there you can create your custom controls.

    Now you only have to do the "Choose Items..." and add this file ONCE. If you later on decide to add a new control, create it in MyCustomControls and then rebuild.
    Then your toolbox will have your new control. (It will be displayed automatically with a regular compile if you have AutoToolboxPopulate I think)

    This is unfortunate, because often you want to separate classes into "one class per file". It is horrible that you have to ruin your code architecture just because VS doesn't want to do it your way. :)

    I am not too comfortable with this solution either but if you need to do something quick and you don't care about multiple user controls within a file or just are lazy, this might suit you well. :)

    0 讨论(0)
  • 2020-12-13 12:36

    Symptom 1: The Design Views for Form, UserControl, & Component were FAILING!

    • My Form design view was failing w/ the msg "can not find 'User Control'."
    • If I could get the Form design view to work it was very unstable & corrupted all to hell w/ any change.

    Symptom 2: The UserControl & Component in the Toolbox

    • Were grayed out in the Toolbox & showed a garbled name
    • "Choose item" in the Toolbox context menu showed garbled name & no namespace

    Solution: Set scope to Public in the vb behind UserControl, & Component

    0 讨论(0)
  • 2020-12-13 12:36

    As mentioned here you should tell the visual studio to load your usercontrol in toolbox.

    [ToolboxItem(true)]
    public class PanelTitle : LabelControl  {
    // Whatever code to override LabelControl here...
    }
    
    0 讨论(0)
提交回复
热议问题