标签:
Form1代码
namespace szys { public partial class Form1 : Form { public Form1() { InitializeComponent(); } public static int right = 0; public static int Count = 0; private int t; string path = ".\text1.txt"; int a = 0; private void button5_Click(object sender, EventArgs e) { Count++; StreamWriter baocun1 = File.AppendText("baocun1.txt"); baocun1.WriteLine(textBox1.Text); baocun1.Close(); StreamWriter baocun2 = File.AppendText("baocun2.txt"); baocun2.WriteLine(textBox4.Text); baocun2.Close(); StreamWriter baocun3 = File.AppendText("baocun3.txt"); baocun3.WriteLine(textBox2.Text); baocun3.Close(); richTextBox1.Text += textBox1.Text + textBox4.Text + textBox2.Text + label2.Text + textBox3.Text + "\n"; textBox1.Clear(); textBox4.Clear(); textBox2.Clear(); } private void btnsave_Click(object sender, EventArgs e)//保存已出试题; { SaveFileDialog TxtSaveDialog = new SaveFileDialog(); TxtSaveDialog.Filter = "文本文档(*.txt)|*.txt"; if (File.Exists(path)) { this.richTextBox1.LoadFile(path, RichTextBoxStreamType.PlainText); MessageBox.Show("保存成功", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); this.richTextBox1.Clear(); btnsave.Enabled = false; } else { if (TxtSaveDialog.ShowDialog() == DialogResult.OK) { this.richTextBox1.SaveFile(TxtSaveDialog.FileName, RichTextBoxStreamType.PlainText); MessageBox.Show("保存成功", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); this.richTextBox1.Clear(); btnsave.Enabled = false; button1.Visible = true; } } } private void button1_Click(object sender, EventArgs e)//打开试题; { OpenFileDialog TxTOpenDialog = new OpenFileDialog(); TxTOpenDialog.Filter = "文本文档(*.txt)|*.txt"; if (TxTOpenDialog.ShowDialog() == DialogResult.OK) { path = TxTOpenDialog.FileName; this.richTextBox2.LoadFile(TxTOpenDialog.FileName, RichTextBoxStreamType.PlainText); btnsave.Enabled = false; button1.Enabled = false; MessageBox.Show("打开成功", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } } private void button2_Click(object sender, EventArgs e)//添加算式题; { textBox1.Enabled = false; textBox2.Enabled = false; textBox4.Enabled = false; textBox1.BackColor = Color.Yellow; textBox4.BackColor = Color.Yellow; textBox2.BackColor = Color.Yellow; textBox3.BackColor = Color.Yellow; string[] m = new string[100]; m = File.ReadAllLines("baocun1.txt"); textBox1.Text = m[a]; string[] n = new string[100]; n = File.ReadAllLines("baocun2.txt"); textBox4.Text = n[a]; string[] v = new string[100]; v = File.ReadAllLines("baocun3.txt"); textBox2.Text = v[a]; a++; } private void textBox3_MouseClick(object sender, MouseEventArgs e)//计时; { label3.Text = t.ToString(); timer1.Enabled = true; timer1.Interval = 1000; timer1.Start(); } private void timer1_Tick(object sender, EventArgs e) { t = t + 1; label3.Text = t.ToString(); } private void button3_Click(object sender, EventArgs e) { MessageBox.Show("一共用时" + label3.Text + "秒"); Form2 frm2 = new Form2(); frm2.ShowDialog(); } private void button4_Click(object sender, EventArgs e) { //调用; szys.celuemoshi.Sub.yunsuanfu clacuter = new szys.celuemoshi.Sub.yunsuanfu(textBox4.Text); int result = clacuter.Calculation(int.Parse(textBox1.Text), int.Parse(textBox2.Text)); if (textBox3.Text==result.ToString()) { MessageBox.Show("恭喜你,小朋友!回答正确!"); right++; Count++; } else { MessageBox.Show("回答错误,继续加油!小朋友"); Count++; } textBox1.Clear(); textBox2.Clear(); textBox3.Clear(); textBox4.Clear(); } } }
Form2代码
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace szys { public partial class Form2 : Form { public Form2() { InitializeComponent(); } private void Form2_Load(object sender, EventArgs e) { textBox1.Text = Form1.Count.ToString(); textBox2.Text = Form1.right.ToString(); textBox4.Text = ((Form1.right / (double)(Form1.Count)) * 100).ToString() + "%"; } } }
标签:
原文地址:http://www.cnblogs.com/twinkle-0908/p/5004904.html