• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 176
  • Last Modified:

Closing Forms

Hi

When my program loads it will show a login form that i have created. After the user has successfully entered a correct username and password a form is loaded depending on their privelleges. What i want to know is how do you close this main form without shutting down the whole program as it does.

if I open another form then go me.close() the program will shutdown. I can hide the form but when the user closes the other window i displayed to them the program will stay running.

Is there anyway to close the main form without shutting down the program?

thanks
0
adam_pedley
Asked:
adam_pedley
  • 5
  • 3
  • 2
  • +2
1 Solution
 
anvCommented:
try this

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim fr As New Form2()
        fr.Show()
        Me.Hide() 'hide current form
    End Sub
0
 
adam_pedleyAuthor Commented:
if I open another form then go me.close() the program will shutdown. I can hide the form but when the user closes the other window i displayed to them the program will stay running.
0
 
anvCommented:
use
the keyword

 End
in the event when u want to close the whole application
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
adam_pedleyAuthor Commented:
how would you specify the event of a form closing
0
 
anvCommented:
hi adam_pedley

what i mean was
when say on form2 u have a button called Close when this button is clicked u want to close the whole application..

then in the click event of close add the statement
End

and the application will close..

0
 
adam_pedleyAuthor Commented:
but like vb6 isnt there an event that on closing the form, code can be run?
0
 
RonaldBiemansCommented:
Hi Adam,

Question

Some users can get a different form depending on their priviliges,

or

the same form with different controls ?
0
 
adam_pedleyAuthor Commented:
different form
0
 
RonaldBiemansCommented:
Hi Adam,
 Instead of starting the login form,  make a sub main in a module

like

Imports System.Windows.Forms

Module MainModule
    Public mainForm As mainForm
    Private LoginForm As LoginForm
    Private appContext As ApplicationContext

    Sub Main()
        StartApplication()
        ShowLoginScreen()
        ShowMainForm()
        ReadEvents()
        Cleanup()
    End Sub

    Sub StartApplication()
        appContext = New ApplicationContext()
    End Sub

    Sub ShowLoginScreen()
        LoginForm = New loginForm()
        LoginForm.ShowDialog()
    End Sub

    Sub ShowMainForm()
        mainForm = New MainForm()
        mainForm.Show()
    End Sub


    Sub ReadEvents()
        appContext.MainForm = mainForm
        Application.Run(appContext)
        ' Application will exit when closing mainForm
    End Sub

    Sub Cleanup()
        ' Garbage collection here
    End Sub
End Module
0
 
DotNetLover_BaanCommented:
>>"but like vb6 isnt there an event that on closing the form, code can be run"<< yes there is. Use the "Base Class Event" that is events associated with the form. and pick Form_Closing.
-@Baan
0
 
wguerramCommented:
The form will be runned in another thread, so your app won't exit.
In your main form

Imports System.Threading


 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
       
        Dim t As New Thread(AddressOf RunForm)
        t.Start()
End Sub

 Private Sub RunForm()
        Dim f As New Form1
        Application.Run(f)
 End Sub
0
 
adam_pedleyAuthor Commented:
i decided to run code when the form was closing using the  Handles MyBase.Closed
0

Featured Post

[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

  • 5
  • 3
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now