代码之家  ›  专栏  ›  技术社区  ›  AJ.

在VB.NET WinForms项目的子命名空间中是否可以有表单?

  •  3
  • AJ.  · 技术社区  · 14 年前

    如果我在VB.NET中创建一个新的类库项目,我可以创建子文件夹(a la C#),将WinForm对象添加到这些子文件夹,然后指定一个命名空间:

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

    ProjectRootNamespace.Sub1.Sub2.SomeForm ,这很好。

    但是,如果我在VB.NET中创建一个新的WinForms项目,并尝试相同的操作,则在设计器中会出现以下错误:

    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.

    有没有办法让窗体位于VB.NET WinForms应用程序的子命名空间中,而不是根命名空间中?

    1 回复  |  直到 14 年前
        1
  •  9
  •   John Alexiou    14 年前

    是否同时重命名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