I'm attempting to create an application which requires login, I've been successful in getting the application to hide form 1 (main app) and load straight for form 2 (login) by initializing Application.Run(new Login());
How ever this can easily be bypassed by hitting the close application from the (Login)form. Which will then take you to form1 (MainApplication) I've tried defining on form close to exit the application but run into an issue where by successful logins will also close the entire application. Which is obviously not desired, can someone point me into the right direction of how to handle such an event?
Form1 (Main Application)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace NewApplication1
{
public partial class MainApp : Form
{
public MainApp()
{
InitializeComponent();
Application.Run(new Login());
}
}
}
Form2 (Login)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
namespace NewApplication1
{
public partial class Login : Form
{
public Login()
{
InitializeComponent();
}
private void Login_Click(object sender, EventArgs e)
{
try
{
string mySqlConnection = "datasource=xxxxx;port=3306;username='" + UserName_TXTBX.Text + "';password= '" + Password_TXTBX.Text + "'";
MySqlConnection mySqlConn = new MySqlConnection(mySqlConnection);
MySqlCommand cmd = new MySqlCommand();
cmd.Connection = mySqlConn;
MySqlDataAdapter myDataAdapter = new MySqlDataAdapter(cmd);
MySqlCommandBuilder cb = new MySqlCommandBuilder(myDataAdapter);
mySqlConn.Open();
DataSet ds = new DataSet();
mySqlConn.Close();
Login.close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error");
}
}
private static void close()
{
ActiveForm.Close();
}
}
}
Problem I have is when the form is closed by the "red 'x'" it will close the login form and continue to the MainApplication when I wish for it to exit the entire application.