If I create a new class library project in VB.NET, I can create subfolders (a la C#), add WinForm objects to these subfolders, and then specify a namespace:
Namespace Sub1.Sub2
Public Class SomeForm
Public Sub New()
InitializeComponent()
End Sub
End Class
End Namespace
This resolves as ProjectRootNamespace.Sub1.Sub2.SomeForm
, which is good.
However, if I create a new WinForms project in VB.NET, and attempt the same thing, I get this error in the designer:
The class SomeForm can be designed, but is not the first class in the file. Visual Studio requires that designers use the first class in the file. Move the class code so that it is the first class in the file and try loading the designer again.
Is there a way to have forms in sub-namespaces of a VB.NET WinForms app instead of in the root namespace?
Are you renaming the namespaces in both the Form.vb as well as the Form.Designer.vb? you need to make sure that both files declare the same object.
Example Form.vb
Namespace X
Namespace Y
Public Class Form1
End Class
End Namespace
End Namespace
And Form.Designer.vb
Namespace X
Namespace Y
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class Form1
Inherits System.Windows.Forms.Form
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
...
End Class
End Namespace
End Namespace
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With