C#----Automatic question application

丈夫欲遂平生志,一载寒窗一举汤。这篇文章主要讲述C#----Automatic question application相关的知识,希望能为你提供帮助。
一个基础的简单自动出题程序:C#初学
界面:

C#----Automatic question application

文章图片

 
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Timers;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 自动出题
{
public partial class Form1 : Form
{
int a, b, g, f;
string op;
int result;
Random rnd = new Random();
int score = 0;
int problemNum = -1;
int problemEorroNum = -1;
public Form1()
{
InitializeComponent();
this.Load += Form1_Load;
}
System.Timers.Timer myTimer;
private void Form1_Load(object sender, EventArgs e)
{
label1.Text = " ";
label3.Text = "勾选“ 自动出题” 确认开始 默认间隔时间7秒 7秒钟后开始";
}
private void radioButton3_CheckedChanged(object sender, EventArgs e)
{
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
void myTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
string ans = this.textBox1.Text;
if (this.radioButton1.Checked == true)
{
if (ans == (result).ToString())
{
score += 1;
}
else
{
problemEorroNum += 1;
}
a = rnd.Next(1, 10);
b = rnd.Next(1, 10);
int c = rnd.Next(1);
switch (c)
{
case 0:
op = "+";
result = a + b;
break;
case 1:
op = "-";
result = a - b;
break;
}
problemNum += 1;
label1.Text = a.ToString() + op + b.ToString() + "=";
textBox1.Text = "";
label2.Text = "已出题:" + problemNum.ToString() +
"道 " + "正确:" + score.ToString() +
"道 " + "错误:" + (problemEorroNum).ToString() + "道"
+ "已得分:" + score.ToString() + " 分";
}
else if (this.radioButton2.Checked == true)
{
if (ans == (result).ToString())
{
score += 1;
}
else
{
problemEorroNum += 1;
}
a = rnd.Next(1, 20);
b = rnd.Next(1, 20);
int c = rnd.Next();
switch (c)
{
case 0:
op = "+";
result = a + b;
break;
case 1:
op = "-";
result = a - b;
break;
}
problemNum += 1;
label1.Text = a.ToString() + op + b.ToString() + "=";
textBox1.Text = "";
label2.Text = "已出题:" + problemNum.ToString() +
"道 " + "正确:" + score.ToString() +
"道 " + "错误:" + (problemEorroNum).ToString() + "道"
+ "已得分:" + score.ToString() + " 分";
}
else if (this.radioButton3.Checked == true)
{
if (ans == (result).ToString())
{
score += 1;
}
else
{
problemEorroNum += 1;
}
g = rnd.Next(1, 20);
f = rnd.Next(1, 20);
int c = rnd.Next(1);
switch (c)
{
case 0:
op = "X";
result = g * f;
break;
}
problemNum += 1;
label1.Text = g.ToString() + op + f.ToString() + "=";
textBox1.Text = "";
label2.Text = "已出题:" + problemNum.ToString() +
"道 " + "正确:" + score.ToString() +
"道 " + "错误:" + (problemEorroNum).ToString() + "道"
+ "已得分:" + score.ToString() + " 分";
}
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
if (this.checkBox1.Checked == true)
{
myTimer = new System.Timers.Timer(7000);
myTimer.Elapsed += myTimer_Elapsed;
myTimer.AutoReset = true;

}
}

private void button1_Click(object sender, EventArgs e)
{
System.Timers.Timer timer = new System.Timers.Timer();
timer.Interval = 6000;
}
【C#----Automatic question application】private void button2_Click(object sender, EventArgs e)
{
System.Timers.Timer timer = new System.Timers.Timer();
timer.Interval = 10000;
}
private void button4_Click(object sender, EventArgs e)
{
myTimer.Enabled = true;
Control.CheckForIllegalCrossThreadCalls = false;
}
private void button3_Click(object sender, EventArgs e)
{
myTimer.Close();
textBox1.Text = "";
label1.Text = "已结束";
label2.Text = "已出题:" + problemNum.ToString() +
"道 " + "正确:" + score.ToString() +
"道 " + "错误:" + (problemEorroNum).ToString() + "道"
+ "已得分:" + score.ToString() + " 分";
}


private void radioButton1_CheckedChanged(object sender, EventArgs e)
{

}
private void radioButton2_CheckedChanged(object sender, EventArgs e)
{

}


}
}

    推荐阅读