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?
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: