C#winform怎样开发简易的20以内加减法口算器?
1、打开Visual Studio2010

2、新建“解决方案”--添加新“项目”

3、窗体及控件布局
1)窗体属性设置:text属性为“20以内加减口算器”;
2)控件数量:两个TextBox控件,一个Lable控件,一个Button控件;
3)布局如图

4、设置控件属性
1)TextBox控件
名称(Name):一个为txt_one;一个为txt_two;
边框(BorderStyle):选择Fixedsingle(显示边框线)
只读(ReadyOnly):选择true;
2)Button控件
名称(Name):输入“btn_strar”
文本显示(Text):输入“开始”


5、添加代码
选择Button控件,双击进入代码输入窗口,输入代码。
代码如下:
namespace 设计
{
public partial class Frm_One : Form
{
public Frm_One()
{
InitializeComponent();
}
int x, y, z;
private void btn_strart_Click(object sender, EventArgs e)
{
Random op = new Random();
z = op.Next(0, 2);
if (z == 1)//加法
{
this.label1.Text = "+";
do
{
Random n = new Random();
x = n.Next(0, 20);
y = n.Next(0, 20);
} while (x + y > 20);
this.txt_one.Text = x.ToString();
this.txt_two.Text = y.ToString();
}
else//减法
{
this.label1.Text = "-";
do
{
Random n = new Random();
x = n.Next(0, 20);
y = n.Next(0, 20);
} while (x <y);
this.txt_one.Text = x.ToString();
this.txt_two.Text = y.ToString();
}
}

6、运行结果如图
您只要点击一次,就出现一道20以内的加法或减法运算。真是快捷方便啊!
