[英]How to open my "logged in" main form, by clicking a button from another Form? and without login again
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;
然后在登录表单中,当用户连接成功时,设置
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.有了这个,你就不需要在加载事件中创建一个新的登录表单,因此,你不会得到另一个登录表单。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.