Jossez
Jossez

Reputation: 35

How to open a different form?

I have 3 forms. Form 1, Form 2 and Form 3 (Login form) When i run the program he just open the first form and i just wanna open the second form. How i can change that? The second form it's a MDI. The objective is open the second form but first the login form,forget about the form 1 for now. When the login is correct then form 2 appear. enter image description here

enter image description here

Upvotes: 0

Views: 67

Answers (2)

Dom Sinclair
Dom Sinclair

Reputation: 2528

Presumably your login form is being used to ensure that however is logging into your application has the right to do so (which implies that you have some sort of verification logic attached to the login form) and if they don't then the application simply wont start. So my suggestion to you would be to create a separate Sub Main procedure and control the start up of your application from there.

If you're not sure how to do that then this should help.

What you want to end up with is something along these lines:

Module Program


Public Sub Main()

    Application.EnableVisualStyles()
    Application.SetCompatibleTextRenderingDefault(False)
    'Add login form here if required
#If DEBUG Then

    Application.Run(New Form1)


#Else
Dim result As DialogResult
    Using dlg As New UserLogin 'substitute the name of your login form
        result = dlg.ShowDialog
    End Using
    If result = DialogResult.OK Then
        Application.Run(New Form1 )

    Else
        Application.Exit()

    End If
#End If


End Sub
End Module

Note that the purpose of the #If Debug block is to avoid constantly having to fill in the login in form during testing.

So with a basic construct like this if your end user is successful in their login then the main form in the application will open, if they are not then the application simply won't run.

Upvotes: 0

ooopsoft
ooopsoft

Reputation: 440

From menu : Project > projectname properties on Application tab you can choose the startup Form.

Upvotes: 0

Related Questions