After 6 hours of analyzing and following this POST solution, my loginform frmLog still wont close. I created two forms in Microsoft visual studio C# window form application. My problem is even if I use different methods and tried everything the login form won’t close or hide. This is very annoying and cause me so much time just on this problem. Please help me.
this is my code in Program.cs where the start up form is initialize.
public static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
frmLog fLogin = new frmLog();
if (fLogin.ShowDialog() == DialogResult.OK)
{
Application.Run(new frmMain());
}
else
{
Application.Exit();
}
}
And this is my login form code which shows the main form frmMain
if the user and password is true they are actually connected to database.
private void btnSubmit_Click(object sender, EventArgs e)
{
Mylibrary a = new Mylibrary("localhost", "root", "", "cashieringdb");
string user = txtLogin.Text;
string pass = txtPassword.Text;
string query = "SELECT * FROM register WHERE username='" + user + "' AND password=MD5('" + pass + "')";
int result = a.Count(query);
if (result == 1)
{
LOGIN_USER = txtLogin.Text;
frmMain main = new frmMain();
main.Show();
this.close
}
else
{
MessageBox.Show("Login Failed! Try Again");
txtLogin.Text = "";
txtPassword.Text = "";
}
}
Please help me solve this problem.
Best Answer
use this
inside frmlog
use