Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Referencing user controls that are contained within the same VB.NET project

I do apologize if this post is a duplicate, but I haven't found anything similar when I searched.

I'm fairly new to VB.NET and I'm currently playing around with user controls, figuring out good programming practices. As far as I understand, to create and use a UserControl, I need to create a project with the UserControl in it, then build the project and use that DLL (add it to Toolbox or otherwise).

My question is this: Is there a way a have a project (a Form with a bunch of things on it) that contains a UserControl written in a *.vb file inside that same Project? If you do that, the DLL (in my case) never gets produced, possibly because the UserControl is never used and building it is simply omitted. Is it perhaps a bad practice to do that altogether? It simply makes sense to me to keep a UserControl as a part of the Project that uniquely uses it. Is there a reason not to do that?

Thanks in advance! = )

SOLUTION: Visual Studio does not automatically include your own controls to the toolbox by default! In order to change that, go to Tools>Options>Windows Form Designer>General and set AutoToolboxPopulate to True. When you build your project next time, your new Control will appear in your Toolbox.

like image 366
Phonon Avatar asked Oct 25 '22 19:10

Phonon


1 Answers

It's a perfectly valid design decision to include a UserControl in a WinForm or WPF project that uses it. If you do this then VS will not create a DLL for the UserControl; instead the UserControl will be built into the assembly your project is producing.

If you did want to reuse a UserControl in multiple projects then you would want to create separate project that generates a DLL that can be reused.

like image 72
Jay Riggs Avatar answered Oct 27 '22 11:10

Jay Riggs