1

I am trying to add a form to a namespace "FormsWeLove" and the only way I found was to add a namespace tag to the form1.vb file and also to the form1.Designer.vb including everything in that file. For the form1.vb:

Namespace FormsWeLove
  Public Class Form1
    Private Sub btnClose_Click(sender As Object, e As EventArgs) Handles btnClose.Click
            Me.Close()
    End Sub   
  End Class
End Namespace

For the form1.Designer.vb:

Namespace FormsWeLove
  <Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()>_
       'rest of the code
  End Class
End Namespace

Would that be the only way to do this? Some posts mentioned that adding the file to a specific folder is supposed to add it to a namespace but it doesn't seem to do the trick here (unless there is no code changed and it doesn't show it in the .vb files but it actually adds them to a namespace at runtime?)

Knowledge Cube
  • 990
  • 12
  • 35
  • The VB.NET IDE does not encourage this, it is pretty incompatible with its desire to hide the Designer.vb file. That doesn't slow you down, but beware the next guy that will maintain the code. You could consider hacking the project item template as [shown here](http://stackoverflow.com/a/3317333/17034) or spinning the form off in its own class library project so the type name is prefixed with the root namespace. – Hans Passant Apr 24 '17 at 15:14
  • I had the feeling that the designer wasn't meant to be modified like that. So if i have a project called myAppUI which contains a folder "FormsWeLove", the way to follow VB.NET intended use would be to make a project out of that folder? So namespaces are meant to be used as a container for projects only? – Daniel Rodriguez Apr 24 '17 at 17:31
  • MSDN seems to propose adding namespaces [link](https://msdn.microsoft.com/en-us/library/ms973231.aspx) without changing the one of the project (they refer to the project's namespace as the rootnamspace) but they don't seem to mention anything about it not working if the .designer.vb is not modified. Do they suppose the tweaks you were talking about? – Daniel Rodriguez Apr 24 '17 at 17:39
  • That article was written before the Designer.vb feature existed. The Partial keyword was added 3 years later. – Hans Passant Apr 24 '17 at 17:47
  • oh! Thank you so much it explains it. Please tell me if you see any official recommendations for the way to proceed to add a namespace inside a project (as it sounds weird that only rootnamespaces related to projects could be used) – Daniel Rodriguez Apr 24 '17 at 17:49
  • I found another question that got answers pointing at something similar but it doesn't seem to mention if it is a good practice or not : [link](http://stackoverflow.com/questions/3943388/is-it-possible-to-have-forms-in-sub-namespaces-of-a-vb-net-winforms-project) – Daniel Rodriguez Apr 24 '17 at 17:55

0 Answers0