I want to use InitializeComponent() when I create a custom control (to be sure everthing is initialized before I use it), but the compiler says it's not declared. But my Designer.vb contains a sub:
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
with all new instances I created.
Why can't I call that?
edit this is how I call InitizialeComponent:
Public Class CustomControlsTextBox : Inherits TextBox
Public Sub New()
MyBase.New()
InitizialeComponent() 'this function is not declared
End Sub
End Class
You should not depend on your Designer.vb's InitializeComponent. Rather, create a new constructor in your
Form1
which will call InitializeComponent()For example:
Now whenever we use the following code:
The
New
constructor in Form1 will be called.