Question Best approach to checking conditions before loading a form.

meisenstein

Member
Joined
Feb 2, 2011
Messages
5
Programming Experience
Beginner
Hi All

Hoping someone can point me in the right direction here. Using VB.Net.

I have a form which asks for a username and password to connect to a MySQL database. Before I load the login form I would like to place a check to see if the connection information is stored in the My.Settings.<connection string>

I am using Sub New() in the Form.Designer to do this by placing the following code:

If My.Settings.cs_Server = "" Or My.Settings.cs_Database = "" then

Application.Run(frmConnectionInformation)

else

InitializeComponent()

End If

The connection form does show but when i close the form there is a blank form that shows up. Why does this happen?

Am I approaching this in the correct way or is there a better or preferred way of doing this. Any help would be greatly appreciated.
 
InitializeComponent must be called, this is where designer puts all generated code to set up the form.
I'd call frmConnectionInformation.ShowDialog and not App.Run because message loop is already started.
 
Hi JohnH

Thank you for the reply.

This is the code i have in place:

Sub New()

If My.Settings.cs_Server = "" Then

frmConnectionInformation.ShowDialog()

Else

InitializeComponent()

End If

End Sub

However when i close the connection form for some reason it pops up a blank form which i then need to close in order to close the application.

This is when i close the form without doing anything.
 
This is because you never call InitializaComponent.
 
Back
Top