C # simple use of forms,

Source: Internet
Author: User

C # simple use of forms,

From today on, we started to learn about window form. Today, we learned how to use some controls and events. There is no comprehensive theory, so today we will summarize the program. A simple registration page program

Registration page program requirements: 1: modify all control Name attributes 2: logon event detection each control is empty, if it is null, the registration fails. If it is successful, a new form is displayed and "XXX hello!" is displayed on the new form! Welcome to cloud and school learning Net "Enter the form of a horse lamp password three times so the login button is not available 3 minutes later can be used to register information of each data according to Rocky | admin | renyanlei@aliyun.com | 18301412747 | male | football, code written into a text file: public partial class Form1: Form {public Form1 () {InitializeComponent ();} int num = 1; // define num to get the number of input errors private void btnregster_Click (object sender, EventArgs e) {// if it reaches three times, the Registration button cannot use if (num = 3) {this. btnregster. enabled = false;} // define a string to receive text data string user = t His.txt name. text. trim (); string pwd = this.txt pwd. text. trim (); string email = this.txt email. text. trim (); string phone = this.txt phone. text. trim (); // determines whether the user name, password, email address, mobile phone number, gender, and hobby are empty. If it is empty, the system prompts that the registration fails. Otherwise, the system prompts that the registration is successful, enter the next interface if (string. isNullOrEmpty (user) {MessageBox. show ("registration failed, no user name entered! "); ++ Num; // timer accumulation} else if (string. IsNullOrEmpty (pwd) {MessageBox. Show (" registration failed, no password entered! "); ++ Num;} else if (txtaginpwd. Text! = Pwd) {MessageBox. show ("registration failed, Confirm Password must be consistent"); ++ num;} else if (string. isNullOrEmpty (email) {MessageBox. show ("registration failed, no email entered"); ++ num;} else if (string. isNullOrEmpty (phone) {MessageBox. show ("registration failed, no mobile phone number entered"); ++ num;} else if (cbkbasketball. checked = false & cbk1_qiu. checked = false & cbkscore. checked = false) // The registration failure {MessageBox is displayed only when none of them are selected. show ("failed to register. Please select a hobby! "); ++ Num;} else if (radman. checked = false & radwomen. checked = false) {MessageBox. show ("failed to register, please select gender"); ++ num;} else {MessageBox. show ("registered successfully"); Form2 fm = new Form2 (user); // open the Form2 form. Here, a parameter user is input. Fm. show (); this. hide (); // Hide the Form1 form} // create a Regster Text Document and write registration information, which is separated by the separator (|) and string gender = string. empty; string like = string. empty; <br> // determine which gender is selected, and obtain the text if (radman. checked = true) {gender = radman. text;} else {gender = radwomen. text;} // determine which interests are selected, and obtain the selected Text if (this. cbkbasketball. checked) {like + = cbkbasketball. text + ",";} if (this. cbk1_qiu. checked) {like + = cbkw.qiu. text + ",";} If (this. cbkscore. checked) {like + = cbkscore. text + ",";} string [] array = {txtname. text, txtpwd. text, txtemail. text, txtphone. text, gender, like}; // defines an array to receive registration information data string strs = string. empty; foreach (var item in array) {strs + = item; strs = string. join ("|", array); // registration information is separated by a separator in the text document} File. writeAllText ("Regster.txt", strs); // if only the document name is written, the default path is in the bin directory of the project.} Private void btnconsole_Click (object sender, EventArgs e) // cancel the button {txtname. focus (); // Let the user name obtain the Focus txtname again. text = ""; txtpwd. text = ""; txtaginpwd. text = ""; txtemail. text = ""; txtphone. text = ""; radman. checked = false; radwomen. checked = false; cbkbasketball. checked = false; cbk1_qiu. checked = false; cbkscore. checked = false;} private void timerreceivtick (object sender, EventArgs e) {// after three errors are entered, the timer stops inputting the input for 3 minutes and then re-enters this. btnregster. enabled = true;} private void Form1_Activated (object sender, EventArgs e) {txtname. focus (); // first let the User Name text box get Focus}

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.