码迷,mamicode.com
首页 > 其他好文 > 详细

结对编程

时间:2015-10-19 00:32:01      阅读:153      评论:0      收藏:0      [点我收藏+]

标签:

一.需求分析

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

2:在Form2窗体中添加3个Lable控件,3个TextBox控件.

 二.代码

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace 
{
         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();
           }

      }
}

好友合作:夏静蕊   王书博

技术分享

 

结对编程

标签:

原文地址:http://www.cnblogs.com/12345wang/p/4890627.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!