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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T22:45:36+00:00 2026-06-01T22:45:36+00:00

I have a Winforms application that starts up with a login screen. If the

  • 0

I have a Winforms application that starts up with a login screen. If the user’s login credentials are good, this method is called:

public void success()
{
    mainForm index = new mainForm();
    index.Show();
    this.Close();
}

I thought that this would open the mainForm and close the login form, however when I run this, it closes the whole application. Why is that? I’m pretty new to C# and OOP in general, so any tips are appreciated!

I tried doing something like this:
Closing a form and then call another one

But I still got the same result.

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-06-01T22:45:37+00:00Added an answer on June 1, 2026 at 10:45 pm

    Do it like:

    static class Program
     {
      /// <summary>
      /// The main entry point for the application.
      /// </summary>
      [STAThread]
      static void Main()
      {   
        using (Login login = new Login())
        {
         login.StartPosition = FormStartPosition.CenterScreen;
         if (login.ShowDialog() == DialogResult.OK)
         {      
          Application.Run(new Form1(login.strUserName)); //passing the userName to the constructor of form1 (see bellow)
         }
       }
      }
     }
    
    //form1:
     public partial class Form1 : Form
     {  
      string userName; 
      public Form1(string _strUser)
      {   
       InitializeComponent();
       userName = _userName; //a local variable of a form1 class has hold user`s name (userName - which u can call it from within the form1 class!
      }
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a WinForms application (WF), and a Library called by that WinForms application
In a winforms application I have a MyForm.cs that starts to get quite large.
I have a Winforms application that the user uses to take a region based
I have an application (winforms) that downloads a file to user's temporary folder, then
I have written a wrapper application in .Net that starts another WinForms application with
I have a winforms application with a numeric field on a form. This starts
I have a Winforms application that generates its own PrintDocument object for printing. It
We have a WinForms application that uses SQL server to store its data. To
I have a Winforms application that schedules some work using a service. The service
I have a Winforms application that dynamically instantiates external form objects for use 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.