gpt4 book ai didi

vb.net - 是否可以在 VB.NET WinForms 项目的子命名空间中使用表单?

转载 作者:行者123 更新时间:2023-12-01 09:08:34 26 4
gpt4 key购买 nike

如果我在 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 应用程序的子命名空间中而不是在根命名空间中使用表单?

最佳答案

您是否在 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

关于vb.net - 是否可以在 VB.NET WinForms 项目的子命名空间中使用表单?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3943388/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com