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 8008759
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T18:14:12+00:00 2026-06-04T18:14:12+00:00

There is two Forms in my project : Form1 and Form2. There is a

  • 0

There is two Forms in my project : Form1 and Form2.
There is a button in Form1, and what I want to do is closing Form1 and showing Form2 when that button clicked.

First, I tried

Form2 frm = new Form2();
frm.Show();
this.Close();

but as Form1 was closed, Form2 also got closed.
Next, I tried

Form2 frm = new Form2();
frm.Show();
this.Hide();

but there is a disadvantage that the application does not exit when the Form2 is closed.So, I had to put in additional sources in form_FormClosing section of Form2.

Hmm…. I wonder whether this is the right way….So, what is the proper way of handling this problem?

  • 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-06-04T18:14:14+00:00Added an answer on June 4, 2026 at 6:14 pm

    The auto-generated code in Program.cs was written to terminate the application when the startup window is closed. You’ll need to tweak it so it only terminates when there are no more windows left. Like this:

        [STAThread]
        static void Main() {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            var main = new Form1();
            main.FormClosed += new FormClosedEventHandler(FormClosed);
            main.Show();
            Application.Run();
        }
    
        static void FormClosed(object sender, FormClosedEventArgs e) {
            ((Form)sender).FormClosed -= FormClosed;
            if (Application.OpenForms.Count == 0) Application.ExitThread();
            else Application.OpenForms[0].FormClosed += FormClosed;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In a .net project, create two forms {Form1, Form2} and on each form create
I've two nested Forms (form1 and form2) showed modally, i.e. from my MainForm I
Let's say I have two forms in a delphi project, I want to be
There are two forms in my project and I am trying to add the
There are just two forms i knew to retrieve resource values in xml files:
In System.Windows.Forms.Application there are two properties called LocalUserAppDataPath and UserAppDataPath . On this computer
There are two objects. The Windows Form with a button and a progress bar,
I have read a document that they say: In java there two types of
There are two things that seem to be popular nowadays and I was wondering
So I have two forms in my project: MainWindow and Options Form (OptForm; QWidget

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.