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

  • Home
  • SEARCH
  • 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 7556125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T11:47:24+00:00 2026-05-30T11:47:24+00:00

I made a C# Windows Forms application that requires the user to login using

  • 0

I made a C# Windows Forms application that requires the user to login using a form called Form1 as shown below:

// This code is called from Form1

Form2 f = new Form2();
f.Show();

// Then Form1 does some finalization logic and closes itself

After the user logs in, the login form should close and the main application window Form2 should be opened. But the problem I’m running into is that if I call Form2 from Form1, Form1 becomes Form2’s owner, thus closing Form1 closes both forms and ends the application.

How may I call Form2 such that it is independent of Form1?

  • 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-30T11:47:25+00:00Added an answer on May 30, 2026 at 11:47 am

    The problem is not the owner, but that the Windows message loop is tied to Form1. When Form1 closes, so does the application. Look in your Main method:

    Application.Run(new Form1());
    

    The easiest solution is to show your login form (assuming it’s a login form) as a modal dialog, and then begin the windows message loop on Form2:

    static void Main()
    {
        var form1 = new Form1();
        form1.ShowDialog();
        if (form1.LoginSuccessful)
        {
            Application.Run(new Form2());
        }
    }
    

    EDIT:
    Just did some googling and looks like another alternative is custom ApplicationContexts. Never worked with these myself though:

    http://msdn.microsoft.com/en-us/library/system.windows.forms.applicationcontext.aspx

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

Sidebar

Related Questions

I have an ASP.NET web forms application that requires that requires that a user
I made this windows forms application in .net 3.5 (VS c# express) . Now
I'm Using Process.Start from my website to open a windows form application I made
I made a .NET Windows form that allows users to view a particular document
I've got a Windows Forms Application that does some data fetching from various places.
Background : I have a C# Windows Forms application that contains a Windows service
I have a windows form application. On the main form a user will enter
I have a windows forms based application made by another programmer and I need
I have a visual c++ windows form application (empty) made on visual studio 2008
I have a windows forms application that uses excel to generate some reports. Untill

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.