Click here to Skip to main content
15,879,326 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
In windows form application,how to close the particular application after 3 wrong login tries..
Need code for that
Posted
Comments
Sergey Alexandrovich Kryukov 26-Feb-13 23:30pm    
What's the problem. Count three failures, close main window. If you need code for that, write it.
—SA

 
Share this answer
 
Hello

you just take one integer variable for e.g. int count=0

every wrong attempt just increase the variable value like count++

if(count >3)
{
Application.Exit();
}


Happy Coding

Thanks
Abhimanyu
 
Share this answer
 
Hi

You can close the Windows Application using Application.Exit() when the wrong_attempt count is equal to three.

Regards
Willington
 
Share this answer
 
C#
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 WindowsFormsApplication13
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        int ctr;
//textbox1 for username
//textbox2 for password
        private void button1_Click(object sender, EventArgs e)
        {

            ctr = ctr + 1;
            if ((textBox1.Text == "arvind") && (textBox2.Text == "arvind"))
            {
                label1.Visible  = true ;
                label1.Text = "Welcome to Arvind Commmunication";
                ctr = 0;

            }
            else
            {
                if (ctr<3)
                {
                    label1.Visible = true;
                    label1.Text = "Incorrect user name or password try again..";
                    textBox1.Focus();
                }
                else
                {
                    MessageBox.Show("Unauthorized Access.");

                    Close();
                }
                textBox1.Text = "";
                textBox2.Text = "";


            }
        }




    }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900