Button click RRS feed

  • Question

  • Hi everyone,

    I had a question about VisualBasic 2008. I made a form with some information and if u click OK you get to a login page, but if you click Ok you get the login page but the other form does not close. How do I make a form close when you go to login form.

    I hope you guys can read and understand this because my englisch is not that good =)

    Thanks greets s7d3

    Wednesday, August 8, 2018 7:01 PM

All replies

  • Hi

    You have to consider your application 'Shut Down Mode' is set to.

    If it is set to 'When Start Up Form Closes' then if you close your application first form, the application will close (unless you intercept the 'Form.Closing' event and redirect to (say) Form.Hide.

    You might also consider setting the 'Shut Down Mode' to 'When last Form closes' and handle the final shut down yourself.

    To close a Form, you would use <Form>.Close. An alternative would be <Form>.Hide (which simply Hides rather than Closes the Form).

    ' Form1 and Form2
    Option Strict On
    Option Explicit On
    Public Class Form1
      Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        ' This Form is start up form
        ' Create a new Form2
        Dim nf2 As New Form2
        ' Show the new form
        ' close this form
        ' if ShutDownMode is set to
        ' WhenStartUpFormCloses then
        ' this will end application and
        ' the Form2 will never be seen.
        ' if ShutDownMode is set to
        ' WhenLastFormCloses then
        ' the application will continue
        ' until the last form is
        ' explicitly Closed.
      End Sub
    End Class
    EDIT: ShutDownMode can be set via: Solution Explorer (double click on MyProject). Application Tab. ShutDown Mode.

    Regards Les, Livingston, Scotland

    • Edited by leshay Wednesday, August 8, 2018 9:23 PM
    • Proposed as answer by Alex Li-MSFT Thursday, August 9, 2018 1:16 AM
    Wednesday, August 8, 2018 9:20 PM