Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4611050
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:12:57+00:00 2026-05-22T01:12:57+00:00

I have a Visual C# project using windowsforms that does not exit when the

  • 0

I have a Visual C# project using windowsforms that does not exit when the X is clicked on any form OTHER than the first form. I think this may have something to do with my form switching?

Currently, I have a Template.CS which is exactly what it sounds like. All of my usage forms extend this by:

public partial class Welcome : ADL.template

Then, I switch between forms by invoking this method:

    public static void formSwitch(Form in_form, Form out_form)
    {
        in_form.Hide();
        out_form.Show();          
    }

Called by:

Program.formSwitch(this, new frmUserInput());

What i think is happening here is, the X is closing the Form NOT the application because the starting form is Hidden, not closed. Is there a better way for me to switch between forms?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T01:12:57+00:00Added an answer on May 22, 2026 at 1:12 am

    Well before answering your question, I should point out that Hide doesn’t actually close your form, it only (as the name implies) hides it. So as time goes on, you’ll keep piling on forms until you either run out of GDI objects or out of memory, either way you’ll crash.

    You are kind of correct about the reason why your application isn’t closing though: even though you close the current form, all your other forms are still loaded so your application won’t end.

    To fix this, the best way would be to actually close your forms when you don’t need them anymore. You won’t even have to add any code to close your application then.

    Now if you don’t want to do that for whatever reason, you can always just call Application.Exit. I strongly discourage you to pursue this “solution” though.

    Edit: as for a possible solution, you could change Program.cs to something like:

    static class Program
    {
      static Form NextForm=new frmLogin();   // or whatever your first form is
      static public void SetNext(Form next) { NextForm=next; }
      static void Main()
      { 
        while(NextForm!=null)
        {
          Form _next=NextForm;
          NextForm=null;      // so it closes at the end
          Application.Run(NextForm);
        }
      }
    }
    

    And then your formSwitch would become:

    public static void formSwitch(Form in_form, Form out_form)
    {
        Program.SetNext(out_form);
        in_form.Close();
    }
    

    It looks weird because your workflow is weird for a Windows program. This is more the workflow of a 1970 FORTRAN program running in DOS.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have Visual Studio 2010 on Windows 7. My project is using the .net
I have upgrade the project from framework3.5 to framework4.0.Right Now i am using Visual
I have a desktop application that on first execution prompts for the connection details
I have Visual Studio 2010 solution of 2 projects: c# and c++ c++ project
so I have a Win32 consol project using libraries like openCV and FFmpeg (builds).
I'm using vs 2010 and have a web application project. I currently use the
I have a Visual Studio 2010 Database project, from which I want to generate
I'm using visual studio and I'd like to have a paper copy of my
I am using Visual Studio 2008 Database Project GDR2 to manage multiple databases and
We have a couple of winforms applications that host a bunch of icons in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.