5.c#winform Base Login failed three times exit system

Source: Internet
Author: User

Goal:

Login interface, login error three times to exit the program. Suppose the username password is admin, 888888,
Case-insensitive, (Error-prone: Local variables and class variables)

The value of the variable is destroyed each time the local variable is run, and is reinitialized the next time it is run.
The class field, as long as it is an object, keeps the field values of the object as long as the object is not destroyed.


Exit procedure: This.close (); or application.exit ();

Centralized mode for text boxes: Mutiline (multiple lines), PasswordChar (password)

String Datatime (). ToString () (+3 overloads)
Converts the value of the current System.datatime object to its valid string representation

The source code is as follows:

usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;namespaceLogin Error three times program exit { Public Partial classForm1:form {Private intErrortimes =0;  PublicForm1 () {InitializeComponent (); }        Private voidButton1_Click (Objectsender, EventArgs e) {            stringUsername =TextBox1.Text; stringPassword =TextBox2.Text; if(username. Equals ("Admin", stringcomparison.ordinalignorecase) && Password = ="888888") {MessageBox.Show ("Landing Success! "); }            Else             {                /*Error method ******************************* int timeerrors = 0;                 timeerrors++; if (timeerrors>= 3) {MessageBox.Show ("Too many errors, the program is about to exit!")                     ");                 Application.exit (); }                 **********************************/                /************************************* * The value of the variable is destroyed each time the local variable is run, and is reinitialized the next time it is run.                  * And the Class field, as long as it is an object, keeps the field values of the object as long as the object is not destroyed. * ************************************/Errortimes++; if(Errortimes >=3) {MessageBox.Show ("too many errors, the program is about to quit! "); Application.exit ();//Exit Procedure: This.close (); or application.exit ();} MessageBox.Show ("account or password is incorrect, login failed! "); }        }        Private voidButton2_Click (Objectsender, EventArgs e) {            /*string Datatime (). ToString () (+3 overloads) * Converts the value of the current System.datatime object to its valid string representation*/Textbox3.appendtext (DateTime.Now.ToString ()+"\ n"); /** TextBox3.Text = TextBox3.Text + DateTime.Now.ToString () + "\ n";            * Although this may also be used, it is not recommended. */        }    }}

Program run:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.