Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Mobile Development
  3. Mobile
  4. form closing

form closing

Scheduled Pinned Locked Moved Mobile
questionhelp
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Deepali Khalkar
    wrote on last edited by
    #1

    I wanted to close a previous form after calling the next form. How do i do that? I have many form in my application. When i exit the application using the following code all the forms are closed one by one. Instead i want to close the previous form after calling the next form in order to avoid the closing of all the forms after exit. Please help. DialogResult result = MessageBox.Show("Do you want to exit?", "Exit-Window", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); if (result == DialogResult.OK) Application.Exit(); I have tried with the following code but the application exits automatically. The code is written on the command button on Form1. private void button1_Click(object sender, EventArgs e) { Form2 frm2 = new Form2(); frm2.Show(); this.Close(); } :)

    J 1 Reply Last reply
    0
    • D Deepali Khalkar

      I wanted to close a previous form after calling the next form. How do i do that? I have many form in my application. When i exit the application using the following code all the forms are closed one by one. Instead i want to close the previous form after calling the next form in order to avoid the closing of all the forms after exit. Please help. DialogResult result = MessageBox.Show("Do you want to exit?", "Exit-Window", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); if (result == DialogResult.OK) Application.Exit(); I have tried with the following code but the application exits automatically. The code is written on the command button on Form1. private void button1_Click(object sender, EventArgs e) { Form2 frm2 = new Form2(); frm2.Show(); this.Close(); } :)

      J Offline
      J Offline
      Joel Ivory Johnson
      wrote on last edited by
      #2

      Application.Exit is made to terminate an application regardless of which form is active. And if you close the main form (the very first form that appears when your application is started) then the application will terminate. To perform what you wish to accomplish you have several methods available. One method is that instead of closing the main form hide it whn ever you invoke a child form and then redisplay it when the child form closes. Depending on how many forms you have in your application you may want to make some of the forms seperate executables to keep memory usage low. Lastly the method that I use is to modify the Main method of the program. By default the Main method will just instantiate Form1 and then let its message processing loop run until the form closes. When I need to do what you are trying to do I alter the main method so that it will open a form and let it run but after that form closes I check to see what it was closed. If it were closed because the user needed to go to a different form then I instantiate that new form and allow its message processing loop to run. OTherwise I allow the MAin method to exit (thus terminating the application).

      Joel Ivory Johnson

      Meet my dev team: RDA Architecture Evangelist Team Blog

      My site: J2i.net

      Twitter: J2iNet

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups