I made a usercontrol in my project, and after building project, I need to put it in my toolbox, and use it as a common control. but i can't. the UserControl
is in my project namespace, and I tried Choose Item
in right click menu, but I didn't find a way to add it.
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
- How to know full paths to DLL's from .csproj f
Right-click on toolbar then click on "choose item" in context menu. A dialog with registered components pops up. in this dialog click "Browse" to select your assembly with the usercontrol you want to use.
PS. This assembly should be registered before.
The issue with my designer was 32 vs 64 bit issue. I could add the control to tool box after following the instructions in Cannot add Controls from 64-bit Assemblies to the Toolbox or Use in Designers Within the Visual Studio IDE MS KB article.
As far as I know you can drag&drop your usercontrol in your current project to the toolbox. The problem is when you choose a different project the user control is gone. So I think you have to build a separate control library project:
In your solution, add a new project, however as a project template choose "Class Library". In THAT project, add a user control, and do everything you need to do. Once that's done, build it, and you'll have yourself a dll file (it can easily be found in the projects bin/debug folder.)
You can add this dll to your toolbox (right click add...) and it will stay there in all projects!
Basic qustion if you are using generics in your base control. If yes:
lets say we have control:
MyComboDropDown will not allow to open designer on it and will be not shown in Toolbox. Why? Because base control is not already compiled - when MyComboDropDown is complied. You can modify to this:
Than after rebuild, and reset toolbox it should be able to see MyComboDropDown in designer and also in Toolbox
Using VS 2010:
Let's say you have a Windows.Forms project. You add a UserControl (say MyControl) to the project, and design it all up. Now you want to add it to your toolbox.
As soon as the project is successfully built once, it will appear in your Framework Components. Right click the Toolbox to get the context menu, select "Choose Items...", and browse to the name of your control (MyControl) under the ".NET Framework Components" tab.
Advantage over using dlls: you can edit the controls in the same project as your form, and the form will build with the new controls. However, the control will only be avilable to this project.
Note: If the control has build errors, resolve them before moving on to the containing forms, or the designer has a heart attack.