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

计应191一组(西)侯金鹏

时间:2021-06-02 19:20:03      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:eve   graphic   ESS   names   osi   details   资源   减法   界面设计   

一、结果呈现
1. 界面设计
窗体界面设计:两个label标签(一个显示题目,一个显示正确率),一个文本框textBox(输入答案),一个列表框listBox(保存做过的题目)。

技术图片

 

 

 

 

 

2. 运行结果呈现

技术图片

 

复制一下啊

 

 

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 (e.KeyChar == 13) //判断是否按下回车键
{
if (Convert.ToInt16(textBox1.Text) == result) //文本内容转换为数字类型并与结果比较
{
Item = label1.Text + textBox1.Text + "?";
right_shu += 1;
}
else
Item = label1.Text + textBox1.Text + "?";
this.listBox1.Items.Add(Item);
this.textBox1.Text = "";
k = (double)right_shu / ti_shu;
label2.Text = "共" + ti_shu + "题" + "正确率为:" + "\n\n" + k.ToString();
Chu_ti();
}
}

private void Form1_Load(object sender, EventArgs e)
{
ti_shu = 0;
right_shu = 0;
Chu_ti();
}
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
2.Form.Designer.cs

代码如下(示例):

using System;

namespace test_4_2
{
partial class Form1
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null;

/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}

#region Windows 窗体设计器生成的代码

/// <summary>
/// 设计器支持所需的方法 - 不要修改
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.textBox1 = new System.Windows.Forms.TextBox();
this.listBox1 = new System.Windows.Forms.ListBox();
this.label3 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// label1
//
this.label1.AutoSize = true;
this.label1.Font = new System.Drawing.Font("宋体", 13.8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.label1.Location = new System.Drawing.Point(302, 155);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(70, 24);
this.label1.TabIndex = 0;
this.label1.Text = "题目:";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.label2.Location = new System.Drawing.Point(302, 380);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(109, 20);
this.label2.TabIndex = 1;
this.label2.Text = "正确率为:";
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(449, 155);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(91, 25);
this.textBox1.TabIndex = 2;
this.textBox1.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.TextBox1_KeyPress);
//
// listBox1
//
this.listBox1.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.listBox1.FormattingEnabled = true;
this.listBox1.ItemHeight = 20;
this.listBox1.Location = new System.Drawing.Point(306, 199);
this.listBox1.Name = "listBox1";
this.listBox1.Size = new System.Drawing.Size(234, 164);
this.listBox1.TabIndex = 3;
//
// label3
//
this.label3.AutoSize = true;
this.label3.Font = new System.Drawing.Font("宋体", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.label3.ForeColor = System.Drawing.SystemColors.Desktop;
this.label3.Location = new System.Drawing.Point(323, 55);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(187, 25);
this.label3.TabIndex = 4;
this.label3.Text = "算数加减法运算";
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(880, 526);
this.Controls.Add(this.label3);
this.Controls.Add(this.listBox1);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
this.PerformLayout();

}

#endregion

private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.ListBox listBox1;
private System.Windows.Forms.Label label3;
}
}
————————————————
版权声明:本文为CSDN博主「iceberg7012」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/iceberg7012/article/details/115397345

计应191一组(西)侯金鹏

标签:eve   graphic   ESS   names   osi   details   资源   减法   界面设计   

原文地址:https://www.cnblogs.com/6103a/p/14833530.html

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