0

My codes still executes without the function InitializeComponent() and if I call the function in the private sub AddGA_Shown all my other functions wont print, run and work. I dont understand why this is happening, because on all my other Forms when I don't call InitializeComponent() then the components in that form will not show.

Private Sub AddGA_Shown(sender As Object, e As EventArgs) Handles MyBase.Shown


    showTabGeneralNOAD()

End Sub

Private Sub showTabGeneralNOAD()

    GAMailAddressTxt.Text = "none"
    GAPasswordLastChangeTxt.Text = "none"
    GAAccountStatusBox.Text = "active"
    GADiscriptionTxt.Text = "Not an AD Account"

End Sub

Private Sub cancelBtn_Click(sender As Object, e As EventArgs) Handles cancelBtn.Click

    Me.Close()

End Sub

This is how the form looks like with the InitializeComponent

Jacky
  • 3
  • 3

1 Answers1

0

If you add a constructor - Public Sub New() to your form - It will automatically insert the InitializeComponent method for you.

When you don't provide your own constructor, it is automatically generated for you.

When you create an instance of this form, the constructor runs and will initialise all the components of the form. MyBase.Shown occurs much later and so calling InitializeComponent will break things. You can view the form events order here.

Community
  • 1
  • 1
A Friend
  • 2,750
  • 2
  • 14
  • 23
  • All my other forms does have his own constructor except that one. But I never noticed that it automatically generate the `InitializeComponent`. Thanks – Jacky Dec 06 '16 at 14:05
  • @Jacky : Designer-/autogenerated code is located in the `yourForm.Designer.vb` file. – Visual Vincent Dec 06 '16 at 17:06