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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:33:47+00:00 2026-05-16T08:33:47+00:00

I am having trouble hiding my main form for a login form. Once user

  • 0

I am having trouble hiding my main form for a login form. Once user has logged in to close login form and show main form.

I have been confusing myself that much I have deleted all code and started fresh. I can hide the login form fine.

I was unable to hide the main form called with

Application.Run(new MainForm());

Login form looks like this:

namespace WindowsFormsApplication1
{
    public partial class LoginForm : Form
    {
        public LoginForm()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string username;
            string password;

            username = TB_username.Text;
            password = TB_password.Text;

            if (User.Login(username, password))
            {
                Globals._Login = true;

                // Close login form
                this.Dispose(false);

            }
            else
            {
                MessageBox.Show("Login Failed");
            }

        }
    }
}

I cant figure out how to hide then show the main form once login has passed.

Thanks any examples would be great

  • 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-16T08:33:48+00:00Added an answer on May 16, 2026 at 8:33 am
    1. Use ShowDialog() to open the login form. Then you don’t need to hide or disable the Mainform yourself. In fact, if you want the login form to appear at the beginning of the application, consider showing it before even loading the Mainform:

      static void Main()
      {
          Application.SetCompatibleTextRenderingDefault(false);
          Application.EnableVisualStyles();
          DialogResult result;
          using (var loginForm = new LoginForm())
              result = loginForm.ShowDialog();
          if (result == DialogResult.OK)
          {
              // login was successful
              Application.Run(new Mainform());
          }
      }
      
    2. Inside your login form, in button1_Click, use

      DialogResult = DialogResult.OK;
      

      to close the login form and pass the OK result to the Mainform.
      There is no need for Dispose().

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

Sidebar

Related Questions

Having Trouble with Entity Framework. I have been populating EntityReferences with an EntityKey inorder
Having trouble with a mysql grant statement. I want a user who has: readonly
Having trouble finding a solution for my situation here. Sorry if this has been
I'm having trouble showing and hiding a tag on my page. When the page
Having trouble with some select statements. I have 2 tables. sms_log and sms_messages. sms_log
Having trouble figuring out how to impersonate another user while using aspnet_personalization with Windows
Having trouble with memory management of a third party library. I have the source
I am having some trouble getting a button clicked after submitting a form using
I'm having trouble hiding the contents of some divs in a pseudo-tab set up
I have a simple accordion menu working using jQuery but I'm having trouble styling

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.