Logon window Version 0.5

Source: Internet
Author: User

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/1935554322-0.gif "alt =" y_0040.gif "/> QQ login window we have seen, a rectangular window of course, it is best to long width with gold split than 0.618 that is the best) the preceding controls are simple and elegant. The most important thing in the logon window is not to log on, but to log on. After successful login, we will go to a main form and pass the passed value to the main window. The transfer of values between two forms is the same as the transfer of values between two classes, because each form is controlled by a class. There are generally the following transfer methods: public variables, field attributes, public methods, constructor methods, delegate events, serialization, and so on.

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/1935551102-1.gif "alt =" j_0057.gif "/> first make a simple login form:

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/193555HV-2.png "title =" Capture. PNG "alt =" 185859210.png"/>

Double-click the "Log on" button to enter a class. The error code in this class is used to control the main form:

Namespace frmForm10 {// declare a delegate to pass values. The abstract method does not return values. There is a string-type parameter public delegate void sendLoginidHanlder (string loginid); public partial class frmlogin: form {// define a delegate event public event sendLoginidHanlder sendLoginidEvent; // initialize public frmlogin () {InitializeComponent ();} bool flag = false; /// <summary> /// process the logon button event // </summary> /// <param name = "sender"> </param> // <param name = "e"> </param> private Void btnLogin_Click (object sender, EventArgs e) {// obtain the value string loginid = this.txt login. text; string pswd = this.txt pwd. text; // check whether the fields specified in the database are consistent bool B = CheckLogin (loginid, pswd); if (! B) {// if they are inconsistent, the user will be prompted with the error MessageBox. show ("Logon Name or Password error", "prompt message", MessageBoxButtons. OK, MessageBoxIcon. information);} else {// if they are consistent, the event if (sendLoginidEvent! = Null) {sendLoginidEvent (loginid);} flag = true; // close the current window this. close ();}} /// <summary> /// connect to the database for verification /// </summary> /// <param name = "loginid"> </param> // <param name = "pswd"> </param> // <returns> </returns> private bool CheckLogin (string loginid, string pswd) {string connString = @" server = (local); database = SchoolDB; uid = sa; pwd = 514420 ;"; string SQL = "select * from login where loginid = @ loginid Nd pswd = @ pswd "; MessageBox. show (SQL); SqlParameter parameter1 = new SqlParameter ("@ loginid", loginid); SqlParameter parameter2 = new SqlParameter ("@ pswd", pswd ); sqlConnection conn = new SqlConnection (connString); SqlCommand command = conn. createCommand (); command. commandText = SQL; command. parameters. add (parameter1); command. parameters. add (parameter2); conn. open (); // create an SQL data reader SqlDataReader sd R = command. executeReader (); // There are two types of read results: read, not read) bool result = sdr. read (); return result;} // <summary> // The logon form is being disabled in the FormClosing event) if the test result is incorrect, close the entire application. // </summary> /// <param name = "sender"> </param> /// <param name = "e"> </param> private void frmlogin_FormClosing (object sender, formClosingEventArgs e) {if (! Flag) {Application. Exit ();}}}}

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/1935551102-1.gif "alt =" j_0057.gif "/> to make a main form, after the login is successful, the data is passed into the main form, and displayed. The Code is as follows:

Public partial class frmMain: Form {public frmMain () {InitializeComponent ();} /// <summary> /// subscribe to the delegate event of the logon form in the loading event of the main form /// </summary> /// <param name = "sender"> </ param> // <param name = "e"> </param> private void frmMain_Load (object sender, eventArgs e) {frmlogin f = new frmlogin (); f. sendLoginidEvent + = new sendLoginidHanlder (f_sendLoginidEvent); // display the modal window in the modal window, that is, the window behind the current window cannot be operated without closing) f. showDialog ();} void f_sendLoginidEvent (string loginid) {this. lbllogin. text = loginid ;}}

This is a simple logon form. After successful logon, the login name is passed into the main form.

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/19355562Y-4.png "title =" Capture. PNG "alt =" 193104779.png"/>AdminIs the passed value!

P.s: during the verification process, note that the data in the database is verified. in the database, we will design a table in advance. The fields in the table are the login name and password.

This is the first version of the logon window, and a more complete version will be available later.

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/1935555L7-5.gif "alt =" j_0047.gif "/> Ajax Girl, come on! 650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/1935555L7-5.gif "alt =" j_0047.gif "/>

This article is from the "Ajax girl" blog!

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.