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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:11:53+00:00 2026-05-27T13:11:53+00:00

I have 3 classes: Form1, LoginForm and program. Program holds my main method that

  • 0

I have 3 classes: Form1, LoginForm and program.

Program holds my main method that then runs loginform, if a condition inside login form is met then form1 is run.

What I want it to do is hide loginform just before I show form1.

How do I do this since I can’t use loginform.hide();

Here’s code:

namespace RepSalesNetAnalysis
{
public partial class LoginForm : Form
{
    public  bool letsGO = false;
    public LoginForm()
    {
        InitializeComponent();
    }

    private static DataTable LookupUser(string Username)
    {
        const string connStr = "Server=10asaf;" +
                            "Database=dfafa;" +
                            "uid=bufaf;" +
                            "pwd=dridfsdf;" +
                            "Connect Timdf0;";

        //"Data Source=apex2006sql;Initial Catalog=Leather;Integrated Security=True;";

        const string query = "Select password From dbo.UserTable (NOLOCK) Where UserName = @UserName";
        DataTable result = new DataTable();
        using (SqlConnection conn = new SqlConnection(connStr))
        {
            conn.Open();
            using (SqlCommand cmd = new SqlCommand(query, conn))
            {
                cmd.Parameters.Add("@UserName", SqlDbType.VarChar).Value = Username;
                using (SqlDataReader dr = cmd.ExecuteReader())
                {
                    result.Load(dr);
                }
            }
        }
        return result;
    }

    private void buttonLogin_Click(object sender, EventArgs e)
    {

        if (string.IsNullOrEmpty(textUser.Text))
        {
            //Focus box before showing a message
            textUser.Focus();
            MessageBox.Show("Enter your username", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
            //Focus again afterwards, sometimes people double click message boxes and select another control accidentally
            textUser.Focus();
            return;
        }
        else if (string.IsNullOrEmpty(textPass.Text))
        {
            textPass.Focus();
            MessageBox.Show("Enter your password", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
            textPass.Focus();
            return;
        }

        //OK they enter a user and pass, lets see if they can authenticate
        using (DataTable dt = LookupUser(textUser.Text))
        {
            if (dt.Rows.Count == 0)
            {
                textUser.Focus();
                MessageBox.Show("Invalid username.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                textUser.Focus();
                return;
            }
            else
            {
                string dbPassword = Convert.ToString(dt.Rows[0]["Password"]);
                string appPassword = Convert.ToString(textPass.Text); //we store the password as encrypted in the DB
                //MessageBox.Show
                Console.WriteLine(string.Compare(dbPassword, appPassword));

                if (string.Compare(dbPassword, appPassword) == 0)
                {
                     DialogResult = DialogResult.OK;
                     this.Close();
                }
                else
                {
                    //You may want to use the same error message so they can't tell which field they got wrong
                    textPass.Focus();
                    MessageBox.Show("Invalid Password", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    textPass.Focus();
                    return;
                }
            }
        }

    }
}

}

Am i missing something? heres my main class;

namespace RepSalesNetAnalysis
{
static class Program
{
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        LoginForm fLogin = new LoginForm();
        if (fLogin.ShowDialog() == DialogResult.OK)
        {
            Application.Run(new Form1());
        }
        else
        {
            Application.Exit();
        }
    }
}
}
  • 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-27T13:11:53+00:00Added an answer on May 27, 2026 at 1:11 pm

    Steven this is all wrong ground up.

    there are other ways to do what you need properly having the Main method of your Program class creating a login form and only if login is successful you instantiate and show the main application form.

    check this question/answer for details and examples: How can I close a login form and show the main form without my application closing?

    you in fact need this approach:

    static void Main()
    {
        LoginForm fLogin = new LoginForm();
        if (fLogin.ShowDialog() == DialogResult.OK)
        {
            Application.Run(new MainForm());
        }
        else
        {
            Application.Exit();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a OOP question. I have 3 classes. Program (main class), login form
I have a factory method that generates django form classes like so: def get_indicator_form(indicator,
I have two links with classes (login-form and register-form) relevant to their target forms
I'm looking at some Java classes that have the following form: public abstract class
There are some HTML based games (ie bootleggers.us) that have a simple login form
I have an application that loads a BPL that as inside a simple form.
I have these classes: Form1.cs Server.cs Now when I do in Server.cs form1.startCapture(C:\\test.mp4); Then
I have classes that store data, and methods to go get data for individual
I have classes that are named exactly the same across different plug-ins that I
I have classes that are needed in both my web service and my server.

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.