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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:29:29+00:00 2026-06-17T11:29:29+00:00

Iam creating an instance to the main form on login button click and again

  • 0

Iam creating an instance to the main form on login button click and again creating instance to login form on logout button click. my code is

      if ((txtUsrNm.Text == "Admin") && (txtPswd.Text == "Admin"))
        {
            mainForm mainFm = new mainForm();
            mainFm.userNam = txtUsrNm.Text;
            mainFm.pasWrd = txtPswd.Text;
            mainFm.Show();
            this.Hide();
        }
         else
        {
            MessageBox.Show("Invalid Username or Password.");
        }

and again in logout button

        this.Hide();
        loginFrm lgn = new loginFrm();
        lgn.Show();

If I try to close instead of Hide, the whole application is closing.
By doing this Application.OpenForms count is increasing on every login and logout operations. How to implement the login and logout operations in windows application. Is there any other Idea for Implementing this operation. Thanking you

  • 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-17T11:29:30+00:00Added an answer on June 17, 2026 at 11:29 am

    You need to put your login part in Program.cs , before Application.Run() called
    e.g :

     if (new frmLogin().ShowDialog() == DialogResult.OK)
     {
         Application.Run(new frmMain());
     }
    

    then put login codes in login form. after user logged in, form login will be closed and will set this.dialogresualt = dialogresult.ok;
    e.g :

    if (txtUserName.Text == "blah"
          && txtPassword.Text == "blah")
       {
         txtPassword.BackColor = Color.YellowGreen;
         txtUserName.BackColor = Color.YellowGreen;
         this.DialogResult = DialogResult.OK;
       }
       else
       {
         txtPassword.BackColor = Color.Salmon;
         txtUserName.BackColor = Color.Salmon;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hi there Iam creating a Paypal IPN and i have a pay now button
I am creating a dropdown contact form and you can view the code below:
I am having a problem creating a WCF service instance with a parameter. The
I am creating a GUI with a browse button which I only want to
I am creating a custom UITableViewCell to include an UIImageView and some related text.
Within this program I am creating an class instance. I am trying to make
The first time I open one of my child forms from the main form
I was implementing a singleton pattern.Here,I am creating a new instance of Singleton* in
I am creating a text editor. My text-box control is a subclass of TextBox
I am creating a custom ASP.NET AJAX server control in which multiple instances of

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.