Logon form (1)

Source: Internet
Author: User

We usually use QQ, fetion, and so on, and there is a login interface. Today we have made a simple login form. When paying attention to the login form, we need to know, the logon form is only an interface and a verification process. What is important is what we will do on the main form after login.

After login, go to the main form and start what we want to do. Here we want to upload the login name of the login form to the main form. Here, we transfer the specific operations on the form passed through the class in the class), there are five methods to pass parameters or values between classes: constructor, public field, public attribute, public method, and delegate.

First look at the login form we made:

650) this. width = 650; "title =" Capture. PNG "alt =" 231619189.png" src = "http://www.bkjia.com/uploads/allimg/131228/192I41056-0.png"/>

Next, we will write various Click events in the login form, and pass the login name in the login form to the main form after successful login:

// Declare a delegate to pass the value public delegate void SendLoginIdHandler (string loginId); public partial class frmLogin: Form {// define an event public event SendLoginIdHandler SendLoginIdEvent; public frmLogin () {InitializeComponent ();} bool flag = false; // <summary> // Click the Click Event of the OK button. Click OK, /// to trigger this event, and determine whether the entered username and password are correct. // here, the default username and password are both admin and correct. // </summary> // <param name = "sender"> </param> // <param name = "e"> </param> priv Ate void btnOK_Click (object sender, EventArgs e) {// obtain the value string loginId = this.txt LoginId. text; string loginPwd = this.txt LoginPwd. text; // determine whether the user name and password are correct. if incorrect, a modal form is displayed and the logon name or password is incorrect if (! (LoginId = "admin" & loginPwd = "admin") {MessageBox. show ("Logon Name or Password error"); // return after the logon name or password is incorrect, and ask the user to re-enter return;} // if this step can be performed, the input is correct, login ends. The login form is closed. The main form flag = true is displayed below; // if the event is not empty, the event if (SendLoginIdEvent! = Null) {SendLoginIdEvent (loginId);} this. close () ;}/// <summary> // The FormClosing event in the login form. When flag = false, the logon fails, /// close the logon form and exit the entire application. /// </Summary> /// <param name = "sender"> </param> /// <param name = "e"> </param> private void frmLogin_FormClosing (object sender, formClosingEventArgs e) {if (flag = false) {Application. exit () ;}/// <summary> // Click the cancel button event, click CLOSE login form /// </summary> /// <param name = "sender"> </param> /// <param name = "e"> </param> private void btnCancel_Click (object sender, eventArgs e) {this. close ();}

The code in the main form is as follows:

Public frmMain () {InitializeComponent ();} private void frmMain_Load (object sender, EventArgs e) {// create a login form object frmLogin frm = new frmLogin (); // subscribe to the event frm. sendLoginIdEvent + = new SendLoginIdHandler (frm_SendLoginIdEvent); // display the logon form frm. showDialog ();} void frm_SendLoginIdEvent (string loginId) {// value passed in through delegation this. label1.Text = loginId ;}

650) this. width = 650; "title =" 1.PNG" alt = "002257541.png" src =" http://www.bkjia.com/uploads/allimg/131228/192I41Z8-1.png "/>

This is the login name passed in after successful login.

P.S. login form: 1: Not too large, without the minimization or maximization button; to be beautiful, we usually see a moderate size of the login form)

2: fixed size; fixed location for Windows Forms)

3: The form is in the center;

4: Class names should be standardized;

5: note that the format is thick, and the left Qinglong and right Baihu are displayed)

This article from the "Lanting drunk beauty" blog, please be sure to keep this source http://7607889.blog.51cto.com/7597889/1303650

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.