VB.Net - How to put a WinForm in a Namespace


There maybe an easier way to do this and if so, leave a comment, I’d like to hear it. Basically, I was organizing some reusable WinForms I have into a hierarchy inside of a class library. It’s my understanding that C# will automatically put forms into a given namespace based on the folder you drop the form into inside of your solution. No such dice with Visual Basic. In VB it doesn’t take long at all however, but there’s an extra step.

  1. Go into your code for the form and put the Namespace tag around the Public Class for your form. This is all I thought you’d have to do.. but when you do this, you’ll now get all kinds of errors and warnings from Visual Studio (2008 in my case as of the writing of this) if you try to compile which is why we need step #2.
  2. In the solution explorer, click the button in the toolbar to ‘Show All Files’. Now, underneath of your form you’ll now have another file called YourForm.designer.vb (and maybe a resource file also). Open the designer.vb file and also put the Namespace tags around that Partial Class. The form has to have the designer and if they’re in different namespaces VS will start throwing errors.

Leave a comment

Please note that we won't show your email to others, or use it for sending unwanted emails. We will only use it to render your Gravatar image and to validate you as a real person.