If login is ur startup form u cannot close it else ur application will be closed...

set the form as hide or visible false before showing the other form....

and then show ur main form

Hi harsh01ajmera,

Go to the menubar and select -> project -> Call function -> change Shutdown mode into: When last form closes.

That means that you can close your login form without closing your application.

Check out this way by using DialogResult (and passing data between forms or classes):

'PROGRAM class    
Class Program

    ''' <summary>
    ''' The main entry point for the application.
    ''' </summary>
    <STAThread()>  _
    Private Shared Sub Main()
        Application.EnableVisualStyles
        Application.SetCompatibleTextRenderingDefault(false)
        Dim loginData As String = ""
        Dim l As Login = New Login
        If (l.ShowDialog = DialogResult.OK) Then
            'code returns form login (if you want you can get some data from there and pass it further:
            loginData = l.MYPROPERTY
        End If
        Application.Run(New Form1(loginData))
    End Sub
End Class
' LOGIN:
Public Class Login
    Inherits Form

    Public Property MYPROPERTY As String
    End Property

    Public Sub New()
        MyBase.New
        InitializeComponent
    End Sub

    Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs)
        'all ok..
        'and close login form (and pass data if you want)
        MYPROPERTY = "hi from login"
        Me.DialogResult = DialogResult.OK
    End Sub
End Class
'MAIN FORM:
Public Class Form1
    Inherits Form

    Public Sub New(ByVal loginData As String)
        MyBase.New
        InitializeComponent
        MessageBox.Show(loginData)
        'Do with the data what ever you want to...
    End Sub
End Class

Edited 4 Years Ago by Mitja Bonca

Ill go with Mitja Bonca.
Don't open your Home Screen on Login form's button click event.
Make the login form to return the login status and check,
do appropriate actions(whether to open the home screen or to give user an error message) in the Main function.

that's what Bonca's code illustrates :)

This article has been dead for over six months. Start a new discussion instead.