dynamic_sysop
Well-known member
Hi guys n gals , i have knocked up a little bit of code which may provide usefull.
i guess most people are aware that if you try closing your Main Form, while trying to leave a second Form open ( ie: Form2.Show , Form1.Close ) , you end up with the Application closing completely. well not anymore
in a Module ( with a Sub Main set as the Start-up object ) ...
in Form1 ( which will load as your default form in this instance ) ...
Form2 will now show and Form1 will close without the Application exiting , in form2 , to close the app i put a simple ...
included is a sample source.
i guess most people are aware that if you try closing your Main Form, while trying to leave a second Form open ( ie: Form2.Show , Form1.Close ) , you end up with the Application closing completely. well not anymore
in a Module ( with a Sub Main set as the Start-up object ) ...
Code:
/// add a module to your application , then set its Sub Main as your start-up object
Imports System.Windows.Forms
Module Module1
Sub main()
Dim frmMain As New Form1
frmMain.Show()
Application.Run() /// NOTE : i run the application without a start-up Main form.
End Sub
End Module
Code:
Private closeApp As Boolean = True
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
closeapp = False
Dim frm2 As New Form2
frm2.Show()
Me.Close()
End Sub
Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
If closeApp Then
Application.Exit()
End If
End Sub
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Application.Exit()
End Sub
Attachments
Last edited by a moderator: