• 结对编程


    一.需求分析

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

          }
    }

    好友合作:夏静蕊   王书博

  • 相关阅读:
    springboot 定制错误页面
    Maven私有仓库-使用docker部署Nexus
    centos7 sentry部署指南
    静态文件服务器部署指南
    开始使用ansible
    2016项目开发经验总结及后续计划
    WPF 3D模型 3D场景
    压缩日志的方法
    创建动态视图
    如何 ︰ 执行批量更新和插入使用.NET 提供程序在 C#.NET OpenXML
  • 原文地址:https://www.cnblogs.com/12345wang/p/4890627.html
Copyright © 2020-2023  润新知