How to close main form i. e login form after login and it should not close application

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

Me.Hide()

Or try

yourFormName.Hide()

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 :)

Startup form cant be closed, but it can be hidden.

This is what worked for me

Set login form as startupform, set project property to end application when last form closes and enter Form1.hide()
[assuming form1 is your login form's name] directly into second form in the Form2_load sub.
Done, nothing else required

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.