AJ.*_*AJ. 3 vb.net namespaces visual-studio-2010 winforms
如果我在VB.NET中创建一个新的类库项目,我可以创建子文件夹(一个C#),将WinForm对象添加到这些子文件夹,然后指定一个名称空间:
Namespace Sub1.Sub2
Public Class SomeForm
Public Sub New()
InitializeComponent()
End Sub
End Class
End Namespace
Run Code Online (Sandbox Code Playgroud)
这解决了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应用程序的子命名空间中而不是在根命名空间中使用表单?
您是否在Form.vb和Form.Designer.vb中重命名命名空间?您需要确保两个文件都声明相同的对象.
例 Form.vb
Namespace X
Namespace Y
Public Class Form1
End Class
End Namespace
End Namespace
Run Code Online (Sandbox Code Playgroud)
和'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
Run Code Online (Sandbox Code Playgroud)