473,396 Members | 1,996 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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

384 256MB
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.        }
Sep 8 '08 #1
2 1869
Plater
7,872 Expert 4TB
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.
Sep 8 '08 #2
ziycon
384 256MB
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();
Sep 8 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

13
by: Dan R Brown | last post by:
I have a large form that is generated dynamically in a jsp using xml / xslt. So, to break up this form into several "tabbed" sections, I break up the form using <div> tags. Each <div...
5
by: me | last post by:
I have a Class Library that contains a Form and several helper classes. A thread gets created that performs processing of data behind the scenes and the Form never gets displayed (it is for debug...
1
by: John Michael | last post by:
I have created some password routines to protect certain forms from access without a password. This allows me to create some security for apps that will be used on diff machines for users that...
8
by: Zlatko Matić | last post by:
There is a form (single form) and a combobox. I want that current record of the form is adjusted according to selected value in the combobox. Cuurrent record should be the same as the value in the...
0
by: me | last post by:
I have a Class Library that contains a Form and several helper classes. A thread gets created that performs processing of data behind the scenes and the Form never gets displayed (it is for debug...
2
by: shekar | last post by:
Hi, I am showing data in gridview... But i want to hide one particular column in that gridview but i must not keep that column property visable=false....if i keep false i am getting problem...
5
by: akowald | last post by:
For some reason Form1.hide() won't hide the form. I run this command at form load. I need it to hide because I'm placing an icon on the system tray. Any ideals? I probley changed something that...
2
by: justplain.kzn | last post by:
Hi, I have a table with dynamic html that contains drop down select lists and readonly text boxes. Dynamic calculations are done on change of a value in one of the drop down select lists. ...
1
by: SoNew | last post by:
I have a Database form in Single View for users to look-up and/or enter data. When the form loads the combo box is empty, which I like - but the fields in the form are all filled in with what the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.