简单的加法运算判断正误
using System;using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int a, b, c, d;
radioButton1.Enabled = true;
radioButton2.Enabled = true;
radioButton1.Checked = false;
radioButton2.Checked = false;
Random rnd = new Random();
a = rnd.Next(99);
b = rnd.Next(99);
c = a + b;
d = rnd.Next(c - 1, c + 1);
textBox1.Text = Convert.ToString(a);
textBox2.Text = Convert.ToString(b);
textBox3.Text = Convert.ToString(d);
button1.Enabled = false;
radioButton1.Enabled = true;
radioButton2.Enabled = true;
label3.Text = "请选择";
}
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
int a, b, c, d;
a = Convert.ToInt32(textBox1.Text);
b = Convert.ToInt32(textBox2.Text);
c = Convert.ToInt32(textBox3.Text);
d = a + b;
if (c == d)
{
label3.Text = "判断正确";
}
else
label3.Text = "判断错误";
radioButton1.Enabled = false;
radioButton2.Enabled = false;
button1.Enabled = true;
}
private void radioButton2_CheckedChanged(object sender, EventArgs e)
{
int a, b, c, d;
a = Convert.ToInt32(textBox1.Text);
b = Convert.ToInt32(textBox2.Text);
c = Convert.ToInt32(textBox3.Text);
d = a + b;
if (c == d)
{
label3.Text = "判断错误";
}
else
label3.Text = "判断正确";
radioButton1.Enabled = false;
radioButton2.Enabled = false;
button1.Enabled = true;
}
}
}
中间红色部分为什么要写两遍才能实现Butten和radiobutten两者的enable属性轮流在true和false之间切换!