• 窗体四则运算。


    我用的是窗体来做的  老师教过 比较简单的方法。

    代码:

    using System;

    using System.Collections.Generic;

    using System.ComponentModel;

    using System.Data;

    using System.Drawing;

    using System.Linq;

    using System.Text;

    using System.Windows.Forms;

    namespace szys.c

    {   

      public partial class Form1 : Form  

       {  

           public Form1()      

       {          

       InitializeComponent();      

       }

           private static int     

            Count = 0,     

           right = 0;       

          private void ys()     

        {        

         Random rn = new Random();      

           int i, j;     

            i = rn.Next(11);     

            j = rn.Next(1, 11);         

            textBox1.Text = i.ToString();

             textBox2.Text = j.ToString();    

             textBox3.Text = "";     

           }     

    private void button1_Click_1(object sender, EventArgs e)     

        {        

         label1.Text = "+";       

          label1.Visible = true;       

      }

            private void button2_Click_1(object sender, EventArgs e)     

        {          

                         label1.Text = "-";       

                       label1.Visible = true;     

        }

            private void button3_Click(object sender, EventArgs e)       

      {          

                        label1.Text = "*";        

                                label1.Visible = true;   

          }

            private void button4_Click(object sender, EventArgs e)       

      {         

                          label1.Text = "/";         

                             label1.Visible = true;   

          }   

       private void button5_Click_1(object sender, EventArgs e)

            {      

                       ys();       

                  } 

        private void button6_Click_1(object sender, EventArgs e)      

       {     

            textBox3.Enabled = false;   

              MessageBox.Show("运算结束!");   

          }         

    private void textBox3_KeyDown_1(object sender, KeyEventArgs e)   

          {

                     if (label1.Text == "+")      

           {                

                             int sum;         

                          sum = int.Parse(textBox1.Text) + int.Parse(textBox2.Text);   

                  if (e.KeyCode == Keys.Enter)            

         {              

           if (textBox3.Text == sum.ToString())  

                       {       right++;         

                             Count++;            

                                      }             

            else                

                     Count++;    

                     textBox4.Text = Count.ToString();                                    

                     textBox4.Enabled = false;

                      textBox5.Text = right.ToString();

                      textBox5.Enabled = false;                  

                    ys();      

               }         

        }      

      

            else if (label1.Text=="-")     

            {     int cha;     

                cha = int.Parse(textBox1.Text) - int.Parse(textBox2.Text);   

                  if (e.KeyCode == Keys.Enter)     

                {             

            if (textBox3.Text == cha.ToString())     

                    {             

                right++;               

              Count++;                

         }                   

      else          

                   Count++;      

                   textBox4.Text = Count.ToString();    

                     textBox4.Enabled = false;       

                  textBox5.Text = right.ToString();     

                    textBox5.Enabled = false;                     

                     ys();            

              }        

         }

               else  if (label1.Text=="*")     

            {               

                  int qj;        

             qj  = int.Parse(textBox1.Text) * int.Parse(textBox2.Text);   

                  if (e.KeyCode == Keys.Enter)       

              {                 

        if (textBox3.Text == qj.ToString())    

                     {              

               right++;             

                Count++;          

               }          

               else         

                    Count++;      

                   textBox4.Text = Count.ToString();  

                       textBox4.Enabled = false;

                        textBox5.Text = right.ToString();   

                      textBox5.Enabled = false; 

                     ys();        

             }            

    }           

      if (label1.Text=="/")     

            {           

          double chu;         

            chu  = int.Parse(textBox1.Text) /int.Parse(textBox2.Text);  

                   if (e.KeyCode == Keys.Enter)      

               {      

                   if (double.Parse (textBox3.Text)==chu )   

                      {    

                         right++;   

                          Count++;  

                       }           

              else                  

           Count++;            

             textBox4.Text = Count.ToString();    

                     textBox4.Enabled = false;      

                   textBox5.Text = right.ToString();   

                      textBox5.Enabled = false; 

                  }           

            }            

            }

            }

    }

    思路就是用窗体构建出模型,然后编写代码,用时1小时。

  • 相关阅读:
    vue 组件传值
    ES6 解构赋值
    JS filter的使用
    FormData实现文件上传
    vue+element 表格导出Excel文件
    vue2.0 element-ui中input的@keyup.native.enter='onQuery'回车查询刷新整个表单的解决办法
    vue2.0 element-ui中el-upload的before-upload方法返回false时submit()不生效解决方法
    JavaScript正则表达式检验手机号码、邮箱、ip地址等
    Vue 2.0 pagination分页组件
    angular环境
  • 原文地址:https://www.cnblogs.com/houqiqi/p/4852511.html
Copyright © 2020-2023  润新知