En esta lección aprenderemos a recordar el usuario y contraseña de un formulario logín y almacenarlos en las variables de configuración del proyecto
Código usado en esta lección:
------------------------------------------------------
private void btnIngresar_Click(object sender, EventArgs e)
{
if (chkRecordar.Checked)
{
Properties.Settings.Default.Usuario = txtUsuario.Text;
Properties.Settings.Default.Clave = txtClave.Text;
Properties.Settings.Default.Recordar = chkRecordar.Checked;
Properties.Settings.Default.Save();
Properties.Settings.Default.Reload();
MessageBox.Show("Datos guardados", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
Properties.Settings.Default.Usuario = "";
Properties.Settings.Default.Clave = "";
Properties.Settings.Default.Recordar = false;
Properties.Settings.Default.Save();
Properties.Settings.Default.Reload();
MessageBox.Show("Datos NO guardados", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
private void Form1_Load(object sender, EventArgs e)
{
if (Properties.Settings.Default.Recordar == true)
{
txtUsuario.Text = Properties.Settings.Default.Usuario;
txtClave.Text = Properties.Settings.Default.Clave;
chkRecordar.Checked = Properties.Settings.Default.Recordar;
}
else
{
txtUsuario.Text = "";
txtClave.Text = "";
chkRecordar.Checked = false;
}
}