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

后端 未结 4 610
别那么骄傲
别那么骄傲 2020-12-01 07:14

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 C

相关标签:
4条回答
  • 2020-12-01 07:34

    One user control can't be applied to it ownself. So open another winform and the one will appear in the toolbox.

    0 讨论(0)
  • 2020-12-01 07:41

    I found that user controls can exist in the same project.
    As others have mentioned, AutoToolboxPopulate must be set to True.
    Create the desired user control.
    Select Build Solution.
    If the new user control doesn't show up in the toolbox, close/open Visual Studio.
    If the user controls still aren't showing up in the toolbox, right click on the toolbox and select Reset Toolbox. Then select Build Solution. If they still aren't there, restart Visual Studio.
    There must not be any build errors when the solution is built, otherwise new toolbox items will not be added to the toolbox.

    0 讨论(0)
  • 2020-12-01 07:44

    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

    0 讨论(0)
  • 2020-12-01 07:50

    One way to get this error is trying to add a usercontrol to a form while the project is set to compile as x64. Visual Studio throws the unhelpful: "Failed to load toolbox item . It will be removed from the toolbox."

    Workaround is to design with "Any CPU" and compile to x64 as necessary.

    Reference: https://support.microsoft.com/en-us/kb/963017

    0 讨论(0)
提交回复
热议问题