views:

1974

answers:

2

I'm doing a Windows Forms project in VB.NET, but VB.NET is completely new to me, I'm primarily a C# developer.

In C# Windows Forms/User controls InitializeComponent is called from the form's/control's constructor. When I create same scenario in VB.NET I don't get a constructor and I can't locate a place where InitializeComponent is called.

I need to call my code between InitializeComponent and control's Load event is raised, preferably still in the control's constructor. How do I do this in VB.NET?

+2  A: 

go View Code in your form, and from the right drop down select the New Method

There you can see where InitializeComponent is called and insert your logic.

Your code if your form is empty should look like this.

Public Class Form1

    Public Sub New()

        ' This call is required by the Windows Form Designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.

    End Sub

End Class
Konstantinos
+1  A: 

In VB.NET the constructor is called New and has the following basic signature

Public Sub New()
End Sub

You can of course override it and add custom parameters.

VS 2008 btw will remind you to put the InitializeComponent() method in the constructor in case you forget, as omitting that will lead to strange behaviors of your controls.

Conrad