Coding and Designing Login Form
Steps:
- Add a new Form to your project.
- Add a Label for Header and change the Text properties to Login
- Add two Labels - change the Text properties and set it to username and password.
- Add two Textboxes - change the design name and set it txtUser and txtPass.
- Add three Buttons - Change the Text properties and set it to login.reset and Exit. Also change the design name to btnLogin, btnReset,btnExit respectively.
Coding:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace AttendanceMan
{
public partial class frmLogin : Form
{
Double count = 0;
public frmLogin()
{
InitializeComponent();
}
private void label1_Click(object sender, EventArgs e)
{
}
private void frmLogin_Load(object sender, EventArgs e)
{
this.AcceptButton = btnLogin;
}
private void btnExit_Click(object sender, EventArgs e)
{
this.Close();
}
private void btnReset_Click(object sender, EventArgs e)
{
//txtPass.Text = "";
//txtPass.Text = string.Empty;
txtPass.Clear();
txtUser.Clear();
txtUser.Focus();
}
private void btnLogin_Click(object sender, EventArgs e)
{
string user, pass;
user = "root";
pass = "password";
if ((txtUser.Text == user) && (txtPass.Text == pass))
{
MessageBox.Show("Welcome User");
}
else
{
count = count + 1;
double maxcount = 3;
double remain;
remain = maxcount - count;
MessageBox.Show("Wrong user name or password" +"\t" +remain +"" +"tries left");
txtPass.Clear();
txtUser.Clear();
txtUser.Focus();
if (count == maxcount)
{
MessageBox.Show("Max try exceeded.");
Application.Exit();
}
}
}
}
}
thank u my friend ! you'r jenius :D
ReplyDelete