Is it possible to have forms in the sub-namespace of a VB.NET WinForms project?

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 the namespace:

Namespace Sub1.Sub2
    Public Class SomeForm
        Public Sub New()
            InitializeComponent()
        End Sub
    End Class
End Namespace

It is allowed as ProjectRootNamespace.Sub1.Sub2.SomeFormthat is good.

However, if I create a new WinForms project in VB.NET and try to do the same, I get this error in the constructor:

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 the VB.NET WinForms application namespaces instead of the root namespace?

+3
source share
1 answer

Form.vb, Form.Designer.vb? , .

Form.vb

Namespace X
    Namespace Y
        Public Class Form1

        End Class
    End Namespace
End Namespace

'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
+8

Source: https://habr.com/ru/post/1769764/


All Articles