zoukankan      html  css  js  c++  java
  • 窗体四则运算。

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

    代码:

    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小时。

  • 相关阅读:
    DevComponents DotNetBar 中Ribbon汉化
    类型Universe无法解析程序 集:System.Design,Version=2.0.0.0
    MapXtreme使用编辑工具
    html中汉字乱码
    c#皮肤使用
    c# 中的internal使用
    DonNetBar汉化
    外汇期货学习专帖(转)
    苦难属于悲情的人
    IT规划宜分步走 忌盲目好大喜功(载)
  • 原文地址:https://www.cnblogs.com/houqiqi/p/4852511.html
Copyright © 2011-2022 走看看