I want to extend the basic ControlCollection
in VB.NET so I can just add images and text to a self-made control, and then automaticly convert them to pictureboxes and lables.
So I made a class that inherits from ControlCollection, overrided the add method, and added the functionality.
But when I run the example, it gives a NullReferenceException
.
Here is the code:
Shadows Sub add(ByVal text As String)
Dim LB As New Label
LB.AutoSize = True
LB.Text = text
MyBase.Add(LB) 'Here it gives the exception.
End Sub
I searched on Google, and someone said that the CreateControlsInstance
method needs to be overriden. So I did that, but then it gives InvalidOperationException
with an innerException
message of NullReferenceException
.
How do I to implement this?