在 VB .NET 中的结构声明内向容器添加控件
有没有办法在 VB .NET 的结构声明中向容器添加控件?
我真正想做的是:
Structure LabelContainer
Dim pnlContainer As New Panel
Dim lblTime As New Label
Dim lblStudent As New Label
Dim lblTeacher As New Label
lblTime.Parent = pnlContainer
lblStudent.Parent = pnlContainer
lblTeacher.Parent = pnlContainer
End Structure
但这在 VB .NET 中不起作用。有没有办法达到同样的目的?
Is there any way of adding a control to a container within a structure declaration in VB .NET?
What I would really like to do is:
Structure LabelContainer
Dim pnlContainer As New Panel
Dim lblTime As New Label
Dim lblStudent As New Label
Dim lblTeacher As New Label
lblTime.Parent = pnlContainer
lblStudent.Parent = pnlContainer
lblTeacher.Parent = pnlContainer
End Structure
But this doesn't work in VB .NET. Is there anyway of achieving the same thing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
结构对控件所需事件的处理非常有限,例如创建控件时触发的 InitializeComponent() 事件。有关更多详细信息,请参阅:
http://www.codeproject.com /Articles/8607/Using-Structures-in-VB-NET
您可以做的是创建一个从面板继承的类,例如:
Structures have very limited handling of the events required by controls, such as the InitializeComponent() event that is fired when a control is created. See this for more details:
http://www.codeproject.com/Articles/8607/Using-Structures-in-VB-NET
What you could do is create a class that inherits from a panel instead, for example:
您可以将子添加到您的结构中:
You can add a sub to your Struct: