How to load second Windows form in project

Blake81

Well-known member
Joined
Feb 23, 2006
Messages
304
Location
Georgia, USA
Programming Experience
1-3
I'm giving the IRC bot a rest for awhile, but I'm working on something else to help me learn. I'm trying to make a simple messenger program, and I've included a login form in the project. The form is called LoginForm1. I tried to include the line "LoginForm1_Load()" in my Form1_Load sub, but it says it isn't declared. How would I do that? Thanks.
 
Hello,

Your post has been moved to the Windows Forms forum, a more fitting forum for your topic. Thank you for posting in the best fit forums in the future.
 
Blake81 said:
I tried to include the line "LoginForm1_Load()" in my Form1_Load sub
It seems that calling a procedure from that same procedure would result in an infinite loop, but perhaps I misunderstand.
LoginForm1_Load is an event handling procedure. In my opinion it is not good practice to call an event handling procedure, although you could. Notice the signature of the load sub:
VB.NET:
Private Sub LoginForm1_Load(ByVal sender As System.Object, _
  ByVal e As System.EventArgs) Handles MyBase.Load
At least that's the way it should look, hopefully yours looks similar. Notice that there are parameters in the procedure's signature (sender and e). In order to call this procedure you need to supply those parameters. Calling the procedure without those parameters causes the IDE to look for a different procedure with no parameters since overloading is available in VB.NET.
To call the procedure use something like this:
VB.NET:
LoginForm1_Load(Me, New System.EventArgs())
Now to the way you should hanlde it. Create a seperate procedure containing the code then call that procedure from the load procedure and any other place you want.
 
Back
Top