0

I'm trying to execute a command when a Form was opened, but the command is not executed, can someone help me?

Code:

  Private Sub MenuPrincipal_Load(sender As Object, e As EventArgs)

    MessageBox.Show("You answered yes, yes and no.")

End Sub
KhallP
  • 23
  • 6
  • Does this answer your question? [Syntax for adding an event handler in VB.NET](https://stackoverflow.com/questions/17511140/syntax-for-adding-an-event-handler-in-vb-net) – He3lixxx Jun 27 '21 at 17:09
  • Also see: [How to handle an event (Windows Forms .NET)](https://learn.microsoft.com/en-us/dotnet/desktop/winforms/controls/how-to-add-an-event-handler?view=netdesktop-5.0) – Xingyu Zhao Jul 21 '21 at 01:29

2 Answers2

1

Unless you have an AddHandler somewhere we can't see, you should declare that your Sub handles the event:

Private Sub MenuPrincipal_Load(sender As Object, e As EventArgs) Handles MyBase.Load
                                                                 ^^^^^^^^^^^^^^^^^^^
   ...
Caius Jard
  • 72,509
  • 5
  • 49
  • 80
0

You want to use a command when the form opens. Then put the command in Formload , in the example i use Form2 .

Make a Private Sub and then put the name in Load. Don't know what form you are using but changing is not so hard.

Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    MenuPrincipal()
End Sub

Private Sub MenuPrincipal()

    MessageBox.Show("You answered yes, yes and no.")

End Sub

enter image description here

Bas H
  • 2,114
  • 10
  • 14
  • 23
  • But for only a MessageBox make a sub is a bit to much. You can put the MessageBox in Form Load – Bas H Jun 27 '21 at 14:13