简单算数加减法运算
前言
C#实践开发_Winform 系列开篇:简单算数加减法运算,掌握label、textBox、listBox控件使用。一、结果呈现
1. 界面设计
窗体界面设计:两个label标签(一个显示题目,一个显示正确率),一个文本框textBox(输入答案),一个列表框listBox(保存做过的题目)。
2. 运行结果呈现

二、源码
1.Form.cs
代码如下(示例):
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace test_4_2
{
public partial class Form1 : Form
{
private int ti_shu, right_shu, result;
public Form1()
{
InitializeComponent();
}
private void Chu_ti()
{
Random randobj = new Random();
int a = randobj.Next(10, 100);
int b = randobj.Next(10, 100);
int p = randobj.Next(0, 2);
if (p == 0) //出加法题
{
label1.Text = a.ToString() + " + " + b.ToString() + " = ";
result = a + b;
}
else //出减法题
{
if (a < b)
{
int t = a;
a = b;
b = t;
}
label1.Text = a.ToString() + " - " + b.ToString() + " = ";
result = a - b;
}
ti_shu += 1;
textBox1.Text = ""; //清空答题文本框
}
private void TextBox1_KeyPress(object sender, KeyPressEventArgs e)
{
string Item;
double k;
if (

本文介绍了如何使用C#和Winform进行简单算数加减法运算的界面设计与运行结果呈现,包括Form.cs和Form.Designer.cs的源码示例,以及随机生成加减法题目的设计思路。

5863

被折叠的 条评论
为什么被折叠?



