public partial class Menu : Form
{
// this is my main form, What I really want
//is not re-enter my name and password
//when I call this form from another form button.
public Menu()
{
InitializeComponent();
{
}
unidadesToolStripMenuItem.Enabled = false;
materialesToolStripMenuItem.Enabled = false;
datosToolStripMenuItem.Enabled = false;
chequeoToolStripMenuItem.Enabled = false;
informeToolStripMenuItem.Enabled = false;
proyectoToolStripMenuItem.Enabled = false;
}
// public void MenuDatosComb();
// if()
public bool UsuarioLogueado = false;
private void Menu_Load(object sender, EventArgs e)
{
this.Hide();
Login login = new Login();
login.ShowDialog();
if (login.Logueado == true)
{
this.Show();
UsuarioLogueado = true;
toolStripStatusLabel2.Text = "Usuario: " + login.Resultado.Substring(20);
}
else
{
this.Close();
}
}
Try this approach, not the best but will work for you.
In the Login Form, add a static property like this
public static bool Logueado { get; private set; }
Then in the Login Form, when the user connects successfuly, you set Logueado = true;
Now in your Main Form, in the load event, you just do this :
this.Hide();
if (Login.Logueado == true)
{
// show
}
else
// close
With this, you'll not need to create a new Login form in the load event, thus, you'll not get another login form.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.