06 implement the four-digit provisioner for determining the decimal point input location, and the four-digit decimal point operation

Source: Internet
Author: User

06 implement the four-digit provisioner for determining the decimal point input location, and the four-digit decimal point operation

1 private void txtnumberw.keypress (object sender, KeyPressEventArgs e) 2 {3 // MessageBox. show (int) (e. keyChar )). toString (); // ASCii View 4 // This event may be triggered by multiple text boxes, therefore, use sender to obtain the control 5 TextBox currentTextBox = sender as TextBox; 6 7 if (e. keyChar <'0' | e. keyChar> '9') 8 {9 e. handled = true; 10} 11 if (e. keyChar = 46) // you can enter the decimal point 12 {13 // check whether the number1 text box contains the decimal point 14 if (currentTextBox. text. indexOf (". ") =-1) 15 {16 // The cursor cannot be in the first place, that is, the decimal point cannot appear in the first 17 if (currentTextBox. selectionStart> 0) 18 {19 e. handled = false; 20} 21} 22} 23 if (e. keyChar = 8) // enables the user to enter the backspace key 24 {25 e. handled = false; 26} 27 28} 29 30 private void btnResult_Click (object sender, EventArgs e) 31 {32 try33 {34 double number1 = Convert. toDouble (txtNumber1.Text); 35 double number2 = Convert. toDouble (txtNumber2.Text); 36 37 switch (comboBox1.Text) 38 {39 case "plus": 40 lbResult. text = (number1 + number2 ). toString (); 41 break; 42 case "minus": 43 lbResult. text = (number1-number2 ). toString (); 44 break; 45 case "multiplication": 46 lbResult. text = (number1 * number2 ). toString (); 47 break; 48 case "except": 49 lbResult. text = (number1/number2 ). toString (); 50 break; 51} 52} 53 catch (Exception ex) 54 {55 MessageBox. show ("your input is incorrect" + ex. message); 56} 57} 58 59 private void txtNumber1_TextChanged (object sender, EventArgs e) 60 {61 lbResult. text = ""; 62} 63 64 private void frmFourOperations_Load (object sender, EventArgs e) 65 {66 comboBox1.SelectedIndex = 0; // when the dropdownstyle attribute of combobox is set to list, the initial value cannot be written to the attribute. You need to use this statement to implement 67}

 

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.