Skip to content

Instantly share code, notes, and snippets.

@drmcarvalho
Created November 6, 2016 23:24
Show Gist options
  • Save drmcarvalho/07a7bf283e54f911e6030aace4fa8c66 to your computer and use it in GitHub Desktop.
Save drmcarvalho/07a7bf283e54f911e6030aace4fa8c66 to your computer and use it in GitHub Desktop.
Tela de login.
using System;
using System.Windows.Forms;
namespace ExemploLogin
{
public partial class frmLogin : Form
{
private bool _loginOk = false;
public frmLogin()
{
InitializeComponent();
}
private void frmLogin_FormClosing(object sender, FormClosingEventArgs e)
{
if (_loginOk)
{
DialogResult = DialogResult.OK;
}
}
private void _btnLogin_Click(object sender, EventArgs e)
{
_loginOk = Login(_txtUser.Text, _txtPass.Text);
if (_loginOk)
{
Close();
}
else
{
MessageBox.Show("Usuario ou senha não confere.");
}
}
bool Login(string user, string pass)
{
return _txtUser.Text.Equals("admin") && _txtPass.Text.Equals("123");
}
}
}
using System;
using System.Windows.Forms;
namespace ExemploLogin
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
frmLogin login = new frmLogin();
if (login.ShowDialog() == DialogResult.OK)
{
Application.Run(new MainFormEx());
}
else
{
Application.Exit();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment