Results 1 to 1 of 1

Thread: Closing the Main Form , without Closing the Application.

  1. #1

    Thread Starter
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142

    Closing the Main Form , without Closing the Application.

    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 ) ...
    VB Code:
    1. '/// add a module to your application , then set it's Sub Main as your start-up object
    2. Imports System.Windows.Forms
    3.  
    4. Module Module1
    5.     Sub main()
    6.         Dim frmMain As New Form1
    7.         frmMain.Show()
    8.         Application.Run() '/// NOTE : i run the application without a start-up Main form.
    9.     End Sub
    10. End Module
    in Form1 ( which will load as your default form in this instance ) ...
    VB Code:
    1. Private closeApp As Boolean = True
    2.  
    3.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    4.         closeapp = False
    5.         Dim frm2 As New Form2
    6.         frm2.Show()
    7.         Me.Close()
    8.     End Sub
    9.  
    10.     Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
    11.         If closeApp Then
    12.             Application.Exit()
    13.         End If
    14.     End Sub
    Form2 will now show and Form1 will close without the Application exiting , in form2 , to close the app i put a simple ...
    VB Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.         Application.Exit()
    3.     End Sub
    included is a sample source.
    Attached Files Attached Files
    ~
    if a post is resolved, please mark it as [Resolved]
    protected string get_Signature(){return Censored;}
    [vbcode][php] please use code tags when posting any code [/php][/vbcode]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width