Connecting Tech Pros Worldwide Forums | Help | Site Map

Form.Hide() and Form.Visable = false; Don't Work

Familiar Sight
 
Join Date: Sep 2008
Posts: 255
#1: Sep 8 '08
This function is in a class file, can't get the frmLogin form to hide when a user logins in, the frmMain will open fine though!???

Expand|Select|Wrap|Line Numbers
  1. public void login(string username,string password)
  2.        {
  3.            DBConnect(); //Internal DB connection call
  4.  
  5.            frmLogin login = new frmLogin();
  6.  
  7.            md5 = new MD5CryptoServiceProvider();
  8.            originalBytes = ASCIIEncoding.Default.GetBytes(password);
  9.            encodedBytes = md5.ComputeHash(originalBytes);
  10.  
  11.            QueryString = "SELECT username,password FROM userdat WHERE username='" + username + "'";
  12.            command.CommandText = QueryString;
  13.            try
  14.            {
  15.                Reader = command.ExecuteReader();
  16.                Reader.Read();
  17.                try
  18.                {
  19.                    if (Reader.GetValue(0).ToString() != null)
  20.                    {
  21.                        if ((username == Reader.GetValue(0).ToString()) && (BitConverter.ToString(encodedBytes) == Reader.GetValue(1).ToString()))
  22.                        {
  23.                            login.Hide();
  24.                            new frmMain().Show();
  25.                        }
  26.                        else
  27.                        {
  28.                            MessageBox.Show("Username or password are incorrect.", "Simplicity", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  29.                        }
  30.                    }
  31.                }
  32.                catch(MySqlException)
  33.                {
  34.                    MessageBox.Show("Username is incorrect.", "Simplicity", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  35.                }
  36.  
  37.            }
  38.            catch (MySqlException ex01)
  39.            {
  40.                MessageBox.Show("Error communicating with the database.\nInternal Error Code: x00001\nError Code: "+ex01, "Simplicity", MessageBoxButtons.OK, MessageBoxIcon.Error);
  41.            }
  42.  
  43.            DBDisconnect(); //Internal DB close connection call.
  44.        }

Plater's Avatar
Moderator
 
Join Date: Apr 2007
Location: New England
Posts: 7,161
#2: Sep 8 '08

re: Form.Hide() and Form.Visable = false; Don't Work


You are not hiding your existing login form, you are creating a new one and hiding THAT one.
You will need to hide the instance of the one already opened.
Familiar Sight
 
Join Date: Sep 2008
Posts: 255
#3: Sep 8 '08

re: Form.Hide() and Form.Visable = false; Don't Work


I've added the function to return a boolean value to the login form so if the login details are all correct it'll return a true value so on the login form i have the below if statement and it seems to be working ok, thanks for that Plater.

Expand|Select|Wrap|Line Numbers
  1. validate = dbconn.login(txtUsername.Text, txtPassword.Text);
  2. if (validate)
  3.    this.Hide();
Reply


Similar .NET Framework bytes