views:

21

answers:

1

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?

+3  A: 

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
jalexiou
+1, yup. Have to click the Show All icon in the Solution Explorer window to find that file.
Hans Passant
That was it! Thanks very much.
AJ