• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
夏静蕊
博客园    首页    新随笔    联系   管理    订阅  订阅
结对编程

需求分析

设置Form1窗体,向里面添加8个Lable控件,3个TextBox控件,2个Button控件

 

·代码

 

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

         public partial class Form1 : Form          {        

  public Form1()          

{                

 InitializeComponent();      

    }

 

          public static int Count = 0;     

            public static int right = 0;     

          private void button1_Click(object sender, EventArgs e)      

    {                      

  RandomNum();    

      }                       

        private void RandomNum()        

  { 

 

Random ran = new Random();   

 int n1, n2;            

n1 = ran.Next(1, 11);      

 n2 = ran.Next(1, 11);        

 textBox1.Text = n1.ToString();    

   textBox2.Text = n2.ToString();   

    textBox3.Text = "";       

      Count++;

 

        }

 

    

private void textBox3_KeyDown(object sender, KeyEventArgs e)     

    {    

       int Count;  

         string c = label9.Text;        

   switch (c)      

    {

                case "+":  

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

            break;      

   

        case "-":    

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

            break;          

       case "x":        

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

          break;           

      default:            

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

         break

 

}

 

            if (e.KeyCode == Keys.Enter)         

    {

     if (textBox3.Text == Count.ToString())      right++;  

   RandomNum();          

   }

 

  }

 

        private void label5_Click(object sender, EventArgs e)      

   {    

   label10.Text = "+";        RandomNum();

        }

 

        private void label6_Click(object sender, EventArgs e)       

  {  

    label10.Text = "-";       RandomNum();  

       }

 

        private void label7_Click(object sender, EventArgs e)         {  

    label10.Text = "*";       RandomNum();       

  }

 

        private void label8_Click(object sender, EventArgs e)         {    

   label10.Text = "/";        RandomNum();    

     }

 

           private void button2_Click_1(object sender, EventArgs e)           {    

             textBox3.Enabled = false;            

     Form2 frm2 = new Form2();              

    frm2.ShowDialog();      

     }

    }

}

四·好友合作:夏静蕊 王书博

 

posted on 2015-10-18 22:56  夏静蕊  阅读(151)  评论(1)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3