C # language lesson 1-basic functions of Windows Forms (Login logon Interface ),

Source: Internet
Author: User

C # language lesson 1-basic functions of Windows Forms (Login logon Interface ),

Because of my internship, this cainiao had to quickly access the C # language. Just now, I had to do my graduation design. So I had to do these two things in a self-learning way.

Therefore, text records or various file names in the Code are recorded as graduation design templates. Please look at the inconvenience. (After all, I cannot write code in special specifications for cainiao)

In the course of learning, I recorded the problems and various learned knowledge in the form of diaries or weekly notes. If you are a like-minded cainiao in the same situation as me, let's talk and learn from each other ~

The mistake of the text record or the location that can be optimized. If a great God sees it, I 'd like to give it some advice ~

 

 

 

The general model of my graduation project is similar to QQ chat, so if I don't talk about it, I will first get a login Windows form Login_interface (I don't know how to name it properly at first, I think Baidu, it can make me miserable later, sorry ).

At the beginning, it was quite easy to learn. C # made it very easy to implement many forms functions through simple settings and simple code (many functions can be Baidu, this helps me get started with cainiao.

 

1. windows Forms

What I achieve is that the logon interface is not maximized. You only need to set MaximizeBox to False in the attribute in the lower right corner;

In addition, the BackgroundImage is set to a 2013 QQ background image of Baidu;

 

2. TextBox Control

(This is required for one user name and one password)

I want to implement it in TextBox. When the mouse is not clicked, "Enter the user name" is displayed. When the mouse is clicked, It is blank for information input.

I learned that this process is called focus. The focus acquisition process of TextBox is the mouse clicking process. here we need to create the event Enter and Leave events.

Private void textBox_UserName_Enter (object sender, EventArgs e) {// when the current control gets the focus, the text content becomes blank if (textBox_UserName.Text = "Enter the user name ") {textBox_UserName.Text = ""; textBox_UserName.ForeColor = Color. black;} // when the current control gets the focus, set the background Color textBox_UserName.BackColor = Color. beige;} private void textBox_UserName_Leave (object sender, EventArgs e) {if (textBox_UserName.Text = "") {textBox_UserName.Text = "Enter the user name"; textBox_PassWord.ForeColor = Color. gray;} // when the current control loses focus, set the background Color to white textBox_UserName.BackColor = Color. white ;}

3. Button Control

Create a confirmation button and a Cancel button.

If the user name and password are correct, the user interface is displayed. If the user name and password are incorrect, an error message is displayed)

Private void button#click (object sender, EventArgs e) {if (textBox_UserName.Text = "1" & textBox_PassWord.Text = "1") {this. close ();} else {MessageBox. show ("Incorrect username and password, please enter again ");}}

Click the cancel button to exit the program ).

Private void button_Cancel_Click (object sender, EventArgs e) {if (MessageBox. Show ("what do you want? "," Think clearly! ", MessageBoxButtons. YesNo, MessageBoxIcon. Exclamation) = DialogResult. Yes) {Environment. Exit (0 );}}

Such a basic Login logon interface is basically complete ~ ^ W ^ ~

 

Thank you for your advice ~
 

 

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.